Reputation: 35
<asp:GridView ID="gvInaciveQuestions" runat="server" AutoGenerateColumns="False" OnRowCommand="gvInaciveQuestions_RowCommand">
<Columns>
<asp:TemplateField HeaderText="Selelct">
<ItemTemplate>
<asp:Button ID="btnactive" runat="server" Text="Active" onClick="btnactive_Click" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Question">
</asp:Gridview>
I have added Itemtemplate as Button but it is not firing onclick
event.
Could please any one suggest me ?
Upvotes: 0
Views: 7330
Reputation: 404
you should not use onClick="btnactive_Click"
event here, instead use CommandName
property.
<asp:Button ID="btnactive" runat="server" Text="Active" CommandName="Click" />
In your OnRowCommand
in codebehind implement like this.
protected void gvInaciveQuestions_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Click")
{
//your code here
}
}
I hope this will solve your issue.
- Harsha Ch
Upvotes: 0
Reputation: 460370
Don't DataBind
it on every postback by using the Page.IsPostBack
property, for example in Page_Load
(resuming that the method that you're using for databinding is called BindGridView
):
protected void Page_Load(ovject sender, EventArgs e)
{
if(!IsPostBack)
{
BindGridView();
}
}
Otherwise events aren't triggered and changed values in the grid are overwritten by the values from your (old) DataSource
.
Upvotes: 1