I have a GridView on my page and single column of this view consists of buttons. On clicking these buttons, I want a method to be called which is located at code behind page. I have tried, OnClick of button and OnRowCommand of GridView. However, I still cannot call the function from code behind page.
This is my GridView.
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"
CssClass="formx2" AutoGenerateColumns="False" DataKeyNames="companyName" >
<Columns>
<asp:TemplateField HeaderText="Düzenle" SortExpression="companyName"
开发者_C百科 HeaderStyle-CssClass="colDept">
<ItemTemplate>
<asp:Button runat="server" ID="IncreaseButton" Text="Düzenle"
CommandName="Select" CommandArgument="something"
CssClass="accordionHeader" BorderColor ="White"
Onclick="redirect"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
And my code behind method,
protected void redirect(object sender, EventArgs e)
{
TextBox1.Text = "test";
}
Help would be greatly appreciated, I really stuck at this point.
Thanks in advance.
Something like this
<asp:TemplateField HeaderText="Düzenle" SortExpression="companyName" HeaderStyle-CssClass="colDept">
<ItemTemplate>
<asp:Button ID="IncreaseButton" runat="server"
CommandName="Select"
CommandArgument="<%# CType(Container,GridViewRow).RowIndex %>"
/>
</ItemTemplate>
</asp:TemplateField>
and then code behind
Protected Sub GridView1_RowCommand(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)
If (e.CommandName = "Select") Then
// Retrieve the row index stored in the CommandArgument property.
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
// Retrieve the row that contains the button
Dim row As GridViewRow = GridView1.Rows(index)
// Add code here
End If
End Sub
精彩评论