Reputation: 5044
i created a web application wherein i used the onrowcommand and created the handler in code behind, now i have a button inside the emptytemplate, whenever i click the button, my onRowCommand is not executed. Below is my code.
<asp:GridView ID="grdExternalLinkSection1" runat="server" Width="100%" AutoGenerateColumns="false" CellPadding="5" OnRowCommand="grdExternalLinkSection_RowCommand">
<EmptyDataTemplate>
External Link Title
<asp:TextBox ID="txtExternalLinkTitleEmptySection1" runat="server"></asp:TextBox>
External Link Url
<asp:TextBox ID="txtExternalLinkUrlEmptySection1" runat="server"></asp:TextBox>
<asp:Button ID="btnExternalLinkEmptySection1" runat="server" Text="Add" CommandArgument="1" CommandName="headernew" style="padding:3px; width:56px;" />
</EmptyDataTemplate>
</asp:GridView>
there are more fields but this is what i am talking about. and here is my code behind handler for the RowCommand Event.
protected void grdExternalLinkSection_RowCommand(object sender, GridViewCommandEventArgs e)
{
Response.Write("welcome");
}
it never excutes the handler, and below is my page directive:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="NewsletterASPVersion.ascx.cs" Inherits="RWO_Controls_NewsletterASPVersion" %>
this worked once, and after thereafter never working. does anyone have any idea what could be causing this.
Upvotes: 1
Views: 3173
Reputation: 460138
There are two possible traps that you might have fallen into:
You are rebinding the GridView to it's DataSource on every postback. So always check:
if(!IsPostBack)BindGrid();
grdExternalLinkSection1.DataBind()
when the DataSource is emptyBut then you would not see the EmptyDataTemplate
at all. So i guess that you've fallen into the first trap.
Upvotes: 4