468,532 Members | 1,643 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,532 developers. It's quick & easy.

Gridview wont fire OnRowCommand, help

<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 <ItemTemplateI 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 

--
JP
..NET Software Developer
Aug 9 '07 #1
3 7306
Hi,
I see DataKeyNames missing in your code.For more info refer below forum post:
http://forums.asp.net/t/894348.aspx
--
Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

"JP" wrote:
<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 <ItemTemplateI 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 

--
JP
.NET Software Developer
Aug 10 '07 #2
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

--
JP
..NET Software Developer
"Manish Bafna" wrote:
Hi,
I see DataKeyNames missing in your code.For more info refer below forum post:
http://forums.asp.net/t/894348.aspx
--
Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

"JP" wrote:
<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 <ItemTemplateI 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 

--
JP
.NET Software Developer
Aug 10 '07 #3
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.
--
JP
..NET Software Developer
"Manish Bafna" wrote:
Hi,
I see DataKeyNames missing in your code.For more info refer below forum post:
http://forums.asp.net/t/894348.aspx
--
Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

"JP" wrote:
<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 <ItemTemplateI 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 

--
JP
.NET Software Developer
Aug 10 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by AG | last post: by
3 posts views Thread by AG | last post: by
7 posts views Thread by =?Utf-8?B?cGF0cmlja2RyZA==?= | last post: by
3 posts views Thread by =?Utf-8?B?UGF1bA==?= | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.