Gridview wont fire OnRowCommand, help

G

Guest

<asp:GridView ID="gridResults" runat="server" AutoGenerateColumns="False"
Width="98%" PageSize="25" AllowPaging="True" OnSorting="gridResults_Sorting"
OnPageIndexChanging ="gridResults_PageIndexChange" AllowSorting="True"
OnRowDataBound="gridResults_RowDataBound" EnableViewState="False"
OnRowCommand="gridResults_Command" ></asp:GridView>

Inside a <ItemTemplate> I have an <asp:ImageButton>

The problem is that no matter what I do, clicking the imagebutton or even a
regular button within the grid will not fire the
OnRowCommand="gridResults_Command". It postback the page but never executes
the event.

HOWEVER, if I click on SORT headers or paging footers, OnRowCommand fires
EVERY time. What is the deal? Why doesn’t OnRowCommnad event fire for buttons
in the grid? Even if I set EnableViewState = true on the gridview, nothing
other then sorting and page will fire OnRowCommand ïŒ
 
G

Guest

Thank you for pointing out the missing ket names. Sigh still doesnt solve my
problem. RowCommand wont fire.

I decided to redo the grid and heres what I found when use a fresh grid

STEP A: If I dont put in an EnableViewState attribute in the HTML, then
RowCommand fires.

STEP B: If the attribute is there, regardless of its value, rowcommand wont
fire.

if I perform STEP A, rowcommand will fire until I add my first boundfield
column, then it wont fire. STRANGE

Any other ideas
 
G

Guest

Update:

It appears the issue may have to do with dynamically removing columns from
the grid before it is rendered. My grid in question has 10 columns. Any 4 of
the columns may be removed from the grid depending on the process that is
populating the grid. I have several queries that use the same grid, but not
all the queries have the same columns, so I needed to dynamically remove the
columns so that the DataBind.Eval doesnt fire for columns that dont apply.

My guess is removing these columns screws up ref pointers or something and
causes RowCommnad not to fire for any columns remaining. Seems to me this is
a BUG in .NET

Is there a why I can both hide columns and remove the Eval statements
dynamically. Maybe this will solve the problem instead of removing the whole
column.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top