c# - Get entity object from CommandArgument in GridView RowCommand -
i using gridview bound list<customer>. when rowcommand fired button want able retrieve current row's customer object e.commandargument, so:
protected void gridview_rowcommand(object sender, gridviewcommandeventargs e) { customer customer = (customer)e.commandargument; dosomething(customer); } how assign customer object commandargument before event fired?
i not sure can store complex object in commandargument seems take string or numeric values.
something, have never put practice, convert object json string , use command argument.
for example, using newtonsoft.json , dummy object called foobar
<asp:button id="btnone" runat="server" commandname="click" commandargument='<%#newtonsoft.json.jsonconvert.serializeobject((foobar)container.dataitem) %>' text="click" /> then when handle gridview rowcommand click event, can deserialize object commandargument
foobar foobar = newtonsoft.json.jsonconvert.deserializeobject<foobar>(e.commandargument.tostring()); now works, whether best solution, not sure.
Comments
Post a Comment