I think it's a common problem, saw so many post on it, most of them said check for IsPostback condition in Page_Load and some said to replace image button with link button, I have tried everything but i still cannot get the link button to fire on GirdView
Row Command.
I load the gridview in page load with !IsPostback condition
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
int TotalRows = this.BindGrid(1);
this.FillJumpToList(TotalRows);
}
}
It's not working.
I have this similar kind GridView on another page and it works but doesn't work on another, Can't figure out why. though on the other page where it works, i load the GridView not in page load but on click of button.
bhanu2217
Member
527 Points
458 Posts
GridView RowCommand does not fire
May 02, 2011 03:26 PM|LINK
I think it's a common problem, saw so many post on it, most of them said check for IsPostback condition in Page_Load and some said to replace image button with link button, I have tried everything but i still cannot get the link button to fire on GirdView Row Command.
I load the gridview in page load with !IsPostback condition
My Grid View
<asp:Panel ID="Panel1" runat="server"> <!-- Grid View 1 --> <br /> <div id = "dvGrid1" style ="padding:10px;"> <b><asp:Label ID="lblGridView1Heading" runat="server" Text="Centre Details" Visible="False"></asp:Label></b> <br /> <asp:UpdatePanel ID="UpdatePanel2" runat="server"> <ContentTemplate> <asp:GridView ID="GridView1" runat="server" Width = "100%" AutoGenerateColumns = "false" CellPadding="4" AlternatingRowStyle-BackColor = "#EFF3FB" HeaderStyle-BackColor = "#507CD1" AllowPaging ="true" OnPageIndexChanging = "OnPaging" DataKeyNames = "ID" PageSize = "10" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound" > <Columns> <asp:TemplateField HeaderText = "ID" SortExpression="ID"> <HeaderTemplate> <asp:LinkButton ID="lnkbtnID" runat="server" CausesValidation="false" CommandArgument="ID" CommandName="Sort" ForeColor="#FFFFFF" Font-Underline="false">ID</asp:LinkButton> <asp:PlaceHolder ID="placeholderID" runat="server"></asp:PlaceHolder> </HeaderTemplate> <ItemTemplate> <asp:Label ID="lblID" runat="server" Text='<%# Eval("ID")%>'></asp:Label> </ItemTemplate> <ItemStyle Height="100px" CssClass="AlignCenter" /> </asp:TemplateField> <asp:TemplateField HeaderText = "CentreName" SortExpression="CentreName"> <HeaderTemplate> <asp:LinkButton ID="lnkbtnCentreName" runat="server" CausesValidation="false" CommandArgument="CentreName" CommandName="Sort" ForeColor="#FFFFFF" Font-Underline="false">Centre Name</asp:LinkButton> <asp:PlaceHolder ID="placeholderCentreName" runat="server"></asp:PlaceHolder> </HeaderTemplate> <ItemTemplate> <asp:Label ID="lblCentreName" runat="server" Text='<%# Eval("CentreName")%>'></asp:Label> </ItemTemplate> <ItemStyle Height="100px" CssClass="AlignCenter" /> </asp:TemplateField> <asp:TemplateField HeaderText="CampaignName" SortExpression="CampaignName"> <HeaderTemplate> <asp:LinkButton ID="lnkbtnCampaignName" runat="server" CausesValidation="false" CommandArgument="CampaignName" CommandName="Sort" ForeColor="#FFFFFF" Font-Underline="false">Campaign Name</asp:LinkButton> <asp:PlaceHolder ID="placeholderCampaignName" runat="server"></asp:PlaceHolder> </HeaderTemplate> <ItemTemplate> <asp:Label ID="lblCampaignName" runat="server" Text='<%# Eval("CampaignName")%>'></asp:Label> </ItemTemplate> <ItemStyle Width="150px" Height="30px" CssClass="AlignCenter" /> </asp:TemplateField> <asp:TemplateField HeaderText = "UserName" SortExpression="UserName"> <HeaderTemplate> <asp:LinkButton ID="lnkbtnUserName" runat="server" CausesValidation="false" CommandArgument="UserName" CommandName="Sort" ForeColor="#FFFFFF" Font-Underline="false">UserName</asp:LinkButton> <asp:PlaceHolder ID="placeholderUserName" runat="server"></asp:PlaceHolder> </HeaderTemplate> <ItemTemplate> <asp:Label ID="lblUserName" runat="server" Text='<%# Eval("UserName")%>'></asp:Label> </ItemTemplate> <ItemStyle Width="150px" Height="30px" CssClass="AlignCenter" /> </asp:TemplateField> <asp:TemplateField> <HeaderTemplate> <font color="#FFFFFF"> Delete</font> </HeaderTemplate> <ItemTemplate> <asp:LinkButton ID="Linkbutton2" runat="server" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ID")%>' CommandName="CamDelete" Height="16" Text="<img border = 0 alt='Delete this Contact' src='../images/Icon_Delete.png'>" Width="16"> </asp:LinkButton> <br /><br /> </ItemTemplate> <ItemStyle Height="30px" CssClass="AlignCenter" /> </asp:TemplateField> </Columns> <AlternatingRowStyle BackColor="#EFF3FB" /> </asp:GridView><br /><br /> <asp:Label ID="lblHeadingRecords1" runat="server" Text="No of Records:" Font-Bold="True" Visible="False"></asp:Label> <asp:Label ID="lblRecords1" runat="server" Visible="False" ></asp:Label> <asp:Label ID="lblHeadingJumpTO1" runat="server" Text="Jump To Page:" Font-Bold="True" Visible="False"></asp:Label> <asp:DropDownList ID="ddlJumpTo1" runat="server" OnSelectedIndexChanged = "PageNumberChanged1" AutoPostBack = "true" Visible="False"> </asp:DropDownList> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID = "GridView1" /> </Triggers> </asp:UpdatePanel> </div> </asp:Panel> </div>Code Behind
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { string cmdid = (string)e.CommandArgument; switch (e.CommandName.ToLower()) { case "camdelete": //db.close(); DeleteUserAssociation(cmdid); break; } }Page Load
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { int TotalRows = this.BindGrid(1); this.FillJumpToList(TotalRows); } }It's not working.
I have this similar kind GridView on another page and it works but doesn't work on another, Can't figure out why. though on the other page where it works, i load the GridView not in page load but on click of button.
Also came across this article, didn't help though
http://netpl.blogspot.com/2008/01/imagebutton-in-templatefield-does-not.html
Screenshot of Java script from status bar of page where command fires and from page where command doesn't fire
Visual Studio 2012
Sql Server 2012
-------------------------------------
www.HermesWritings.com
bhanu2217
Member
527 Points
458 Posts
Re: GridView RowCommand does not fire
May 02, 2011 04:41 PM|LINK
Figured out the problem
There is a textbox on the page with required field validator, and the link button was not getting passed bcoz of this, made causes validation="false"
:-)
</div>Visual Studio 2012
Sql Server 2012
-------------------------------------
www.HermesWritings.com