1

I am using a GridView in ASP.net with a pre-added buttons. The GridView's data source is from a list of BookingRowStatus

BookingRowStatus(Row, m_AStatus, m_BStatus, m_CStatus, m_DStatus, m_EStatus, m_FStatus)

The arguments that you can see are the Columns. I added RowCreated event to check m_XStatus to enable/disable the buttons depending on the text inside it ("X" = disable | "Y" = enable).

Next is I added a RowCommand event which should catch the event when a button in GridView is clicked. However, whenever I click the button, it invokes RowCreated instead of RowCommand. I added a break point on both of the said Events and I can see that it doesn't even pass RowCommand; it goes straight to RowCreated.

My question is how do I Invoke RowCommand when I press a button on the DataGrid?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Nov 27 '13 at 04:26

1 Answers1

0

The RowCreated event will fire before the RowCommand event is hit as the child controls (i.e. the rows) will be created on post back before you can access the values from them.

Set a breakpoint in both and see if they are both triggered.

Although your solution should work, an easier solution would be to bind the Button directly to the fields value. E.g.

<asp:Button runat="server" Enabled='<%# Eval("m_XStatus") = "Y" #>' />
codemonkeh
  • 2,054
  • 1
  • 20
  • 36