yokzu

yokzu

  • NA
  • 306
  • 0

"Unable to cast object of type 'System.Web.UI.WebControls.DataGridLinkButton" error

Mar 11 2012 1:51 PM
Hi
I am working on a web project and using Datagrid. I want to edit DataGrid and updating DB. When I edit DataGrid's a row and want to process "Update" command, I get "Unable to cast object of type 'System.Web.UI.WebControls.DataGridLinkButton". Codes are below;

------------------------------------
void command_update(object obj, DataGridCommandEventArgs e)
  {
  DataGrid1.EditItemIndex = e.Item.ItemIndex;

  TextBox txt_id = (TextBox)e.Item.Cells[0].Controls[0];  --> Error at this row
  ...
------------------------------------

And the design side;
------------------------------------
  <asp:DataGrid ID="DataGrid1" RUNAT="server" AutoGenerateColumns="False"  OnUpdateCommand="command_update" OnEditCommand="komut_edit"
  OnCancelCommand="komut_cancel" >

  <Columns>
  <asp:EditCommandColumn EditText="Edit"  CancelText="cancel" UpdateText="Update" HeaderText="Edit" />
  <asp:BoundColumn HeaderText="ID" DataField="ID" />
  </Columns>
  </asp:DataGrid>
-------------------------------

I couldnt solve the problem.

Regards.

Answers (2)