Results 1 to 2 of 2

Thread: [RESOLVED] Asp.Net 2005 + GridView + RowIndex + Sourabh Das

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    220

    Resolved [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.

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    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
    Please mark you thread resolved using the Thread Tools as shown

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width