if i check (!Page.IsPostBack) in page load before binding the gird ; ie
if (!Page.IsPostBack)
Bind(); // this () binds the grid
the row command event is not firing. If I comment the if condition Its perfect. What could be the reason. I dont want to bind the grid each and every time page is post backed :(
rostam
Member
128 Points
56 Posts
Gridview RowCommand does not fire for image button CommandName
Sep 11, 2008 12:29 PM|LINK
I have a gridview - ASP.net 2.0
I have the following code insise my gridview:
<asp:TemplateField HeaderText="Buy Now"> <ItemTemplate> <asp:ImageButton ID="imgbtnAddtoCart" runat="server" Text="Add to Cart" CommandName="AddtoCart" CommandArgument='<%# Eval("DocId") %>' CssClass="searchresult_BuyNowButton" /></ItemTemplate>
</asp:TemplateField>I have a RowCommand event for my gridview:
protected void gvSearchResults_RowCommand(object sender, GridViewCommandEventArgs e){
if (e.CommandName == "AddtoCart"){
Response.Write("----ok");}
}
This event does not fire. !!!!!
If I have a Linkbutton server control, it will fire!!!!!!!
gridview rowcommand Does not fire - Gridview Bug
pkellner
All-Star
24042 Points
3625 Posts
ASPInsiders
Moderator
MVP
Re: Gridview RowCommand does not fire for image button CommandName
Sep 11, 2008 12:38 PM|LINK
They both should work the same. Here is a thread I was involved in where I had the same problem and it turned out to be a viewstate issue.
http://bytes.com/forum/thread547875.html
http://peterkellner.net
Microsoft MVP • ASPInsider
rostam
Member
128 Points
56 Posts
Re: Gridview RowCommand does not fire for image button CommandName
Sep 11, 2008 12:40 PM|LINK
I did not drink my coffee in time.
In my page load event I was not checking for post backs!!!!
if (!Page.IsPostBack){
//bind data
}
When I do this then the rowcommand for the gridview hits!!!!!
Thanks..
pkellner
All-Star
24042 Points
3625 Posts
ASPInsiders
Moderator
MVP
Re: Gridview RowCommand does not fire for image button CommandName
Sep 11, 2008 12:54 PM|LINK
I know the feeling. Good luck.
http://peterkellner.net
Microsoft MVP • ASPInsider
eldhose10
Member
51 Points
57 Posts
Re: Gridview RowCommand does not fire for image button CommandName
Sep 25, 2008 11:03 AM|LINK
blink18jew
Member
199 Points
648 Posts
Re: Gridview RowCommand does not fire for image button CommandName
Oct 07, 2008 12:13 PM|LINK
Deepak Rai
Member
379 Points
98 Posts
Re: Gridview RowCommand does not fire for image button CommandName
Oct 07, 2008 12:37 PM|LINK
Its working in my computer:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "close") { WebMsgApp.WebMsgBox.Show("Close clicked"); } }MCP, MCAD
I love coding at night but bcos of job I cant.
hanimv
Member
111 Points
157 Posts
Re: Gridview RowCommand does not fire for image button CommandName
Dec 01, 2008 01:30 PM|LINK
My prob is just the other way :( :(
if i check (!Page.IsPostBack) in page load before binding the gird ; ie
if (!Page.IsPostBack)
Bind(); // this () binds the grid
the row command event is not firing. If I comment the if condition Its perfect. What could be the reason. I dont want to bind the grid each and every time page is post backed :(
Pleas any one , any idea