developer155
Programmer
Hi, I have a datagrid and on update command I try to set its SelecyedItemIndex to whatever user chose and re-bind datagrid. The problem is that after the page loads, data grid does nto show up! What could be the problem? Here is some code:
public void Edit(object sender, DataGridCommandEventArgs e)
{
//highlight selected row
CategoryDataGrid.EditItemIndex = e.Item.ItemIndex;
CategoryDataGrid.DataSource = Catalog.Tables["Category"].DefaultView;
CategoryDataGrid.DataBind();
}
Here is datagrid:
<asp:datagrid id="CategoryDataGrid" OnEditCommand="Edit" OnDeleteCommand="Delete" OnCancelCommand="Cancel"
DataKeyField="CategoryID" AutoGenerateColumns="False" Runat="server" AlternatingItemStyle-BackColor="Beige"
FooterStyle-BackColor="Silver" FooterStyle-ForeColor="White" ItemStyle-BackColor="White" EditItemStyle-Font-Name="Verdanna"
EditItemStyle-Font-Size="8pt" EditItemStyle-BackColor="yellow" HeaderStyle-BackColor="DarkGreen"
HeaderStyle-Font-Bold="True" HeaderStyle-ForeColor="Beige" BorderColor="black" BorderWidth="1"
CellPadding="3" Font-Name="Verdanna" Font-Size="8pt" EnableViewState=False>
<Columns>
<asp:EditCommandColumn HeaderText="Action" EditText="Edit" CancelText="Cancel" ItemStyle-Wrap="False" HeaderStyle-Wrap="False" />
<asp:TemplateColumn HeaderText="Name">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem,"Name").ToString().Replace("''","'")%>
</ItemTemplate>
</asp:TemplateColumn>
<asp:ButtonColumn HeaderText="Delete" Text="Delete" CommandName="Delete" />
</Columns>
</asp:datagrid>
public void Edit(object sender, DataGridCommandEventArgs e)
{
//highlight selected row
CategoryDataGrid.EditItemIndex = e.Item.ItemIndex;
CategoryDataGrid.DataSource = Catalog.Tables["Category"].DefaultView;
CategoryDataGrid.DataBind();
}
Here is datagrid:
<asp:datagrid id="CategoryDataGrid" OnEditCommand="Edit" OnDeleteCommand="Delete" OnCancelCommand="Cancel"
DataKeyField="CategoryID" AutoGenerateColumns="False" Runat="server" AlternatingItemStyle-BackColor="Beige"
FooterStyle-BackColor="Silver" FooterStyle-ForeColor="White" ItemStyle-BackColor="White" EditItemStyle-Font-Name="Verdanna"
EditItemStyle-Font-Size="8pt" EditItemStyle-BackColor="yellow" HeaderStyle-BackColor="DarkGreen"
HeaderStyle-Font-Bold="True" HeaderStyle-ForeColor="Beige" BorderColor="black" BorderWidth="1"
CellPadding="3" Font-Name="Verdanna" Font-Size="8pt" EnableViewState=False>
<Columns>
<asp:EditCommandColumn HeaderText="Action" EditText="Edit" CancelText="Cancel" ItemStyle-Wrap="False" HeaderStyle-Wrap="False" />
<asp:TemplateColumn HeaderText="Name">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem,"Name").ToString().Replace("''","'")%>
</ItemTemplate>
</asp:TemplateColumn>
<asp:ButtonColumn HeaderText="Delete" Text="Delete" CommandName="Delete" />
</Columns>
</asp:datagrid>