code_junkie

Access Non-Public members of a GridViewCommandEventArgs object

Nov 13th, 2011
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. <asp:GridView ID="MyGridView" runat="server" OnRowCommand="MyGirdView_OnRowCommand">
  2. <Columns>
  3. <asp:TemplateField>
  4. <ItemTemplate>
  5. <asp:LinkButton
  6. id="MyLinkButton"
  7. runat="server"
  8. CommandName="MyCommand"
  9. />
  10. </ItemTemplate>
  11. </asp:TemplateField>
  12. </Columns>
  13. </asp:GridView>
  14.  
  15. protected void MyGirdView_OnRowCommand(object sender, GridViewCommandEventArgs e)
  16. {
  17. //need to access row index here....
  18. }
  19.  
  20. LinkButton lb = (LinkButton) ((GridViewCommandEventArgs)e.CommandSource);
  21.  
  22. LinkButton lb = e.CommandSource as LinkButton;
  23. GridViewRow gvr = lb.Parent.Parent as GridViewRow;
  24. int gvr = gvr.RowIndex;
  25.  
  26. LinkButton lb = (LinkButton) ((GridViewCommandEventArgs)e.CommandSource);
  27. GridViewRow gr = (GridViewRow) lb.Parent.Parent;
  28. var id = gr.RowIndex;
  29.  
  30. var id = ((GridViewRow)((LinkButton)((GridViewCommandEventArgs)e).CommandSource).Parent.Parent).RowIndex;
Add Comment
Please, Sign In to add comment