[RESOLVED] Asp.Net 2005 + GridView + RowIndex + Sourabh Das
Dear All,
I have a GridView:
-----------
<asp:GridView ID="grdAstCls" runat="server" >
<Columns>
<asp:TemplateField HeaderText="..." SortExpression="Select" >
<ItemTemplate>
<asp:Button ID="btnSel" OnClick="btnSel_Click" runat="server" Text="..." />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
------------
Protected Sub btnSel_Click(ByVal sender As Object, ByVal e As EventArgs)
"This code is in CodeBehind file. Here i want to write the code of assigning the selected rows 2nd column data in the textbox txtast."
End Sub
-----------
There will be other columns with this column in begining for each row in the grid. On click of the the button, I want to assign the 2nd column data of that row in a text box(txtast). How do i do that?
Regards.
Re: Asp.Net 2005 + GridView + RowIndex + Sourabh Das
You have to command argument to the button
Pls find the example
Code:
Protected Sub GridView2_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView2.RowCommand
Dim gvr As GridViewRow = GridView1.Rows(e.CommandArgument)
TextBox1.Text = gvr.Cells(0).Text 'The index of the column
End Sub
Protected Sub GridView2_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView2.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim btn As Button = e.Row.FindControl("btnSel")
If Not btn Is Nothing Then
btn.CommandArgument = e.Row.DataItemIndex 'set the Index as command argument
End If
End If
End Sub