I want to find out the bound datarow or datatable of a datagrid on postback. I have a ButtonColumn in the grid. On click of the button, I'开发者_Python百科m trying to determine the datarow so that I can access the primary key and pass it to another page. The primary key is not bound and therefore not visible in the row.
For example I have a list of Customers, with an edit button. On clicking of the edit button, I want to open CustomerEdit.aspx?id=10. I am able to trap the click event on the server side in the DataGridCustomer_ItemCommand event. But am not able to get access to the datarow of the e.Item.ItemIndex.
On postback I'm NOT binding the datagrid. On accessing DataGridCustomer.DataSource, I get "Nothing". Is there a way to get the DataSource or the Datarow?
Thanks
You can't. The DataBind method your are calling the page load method, when it's not a postback will iterate through your source to build controls. After that, the source is not kept...only the resulting controls.
I suggest you to build the url to the edit page instead of relying on postback.
In few words, create a HyperLinkColumn
in your datagrid, and specify the text fields and datafields to build the full url.
精彩评论