• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 624
  • Last Modified:

Getting gridview column value in button click

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" AllowPaging="True"
                            AllowSorting="True" OnPageIndexChanging="GridView2_PageIndexChanging" OnSorting="GridView2_Sorting"
                            PageSize="2">
                            <Columns>
<asp:BoundField DataField="Fnumber" HeaderText="Fnumber" />
    <asp:TemplateField >
                                    <ItemTemplate>
                                        <asp:linkbutton" runat="server" > 
                                    </ItemTemplate>
                                    <ItemStyle Width="120px" />
</Columns>

</GridView>

I want to write onclick code for link button and get the value of  Fnumber.
Please help
0
Angela4eva
Asked:
Angela4eva
1 Solution
 
MrunalCommented:
Hi,
Its very easy.
You can go to design view and then go to edit template for that gridview.
You will get link button there. Just double-click on that.

you will get click event automatically generated.

Hope this helps you.
0
 
HainKurtSr. System AnalystCommented:
here it is, there are two solutions, use either one...
        <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" AllowPaging="True"
            AllowSorting="True" OnRowCommand="GridView2_RowCommand" 
            PageSize="2">
            <Columns>
                <asp:BoundField DataField="Fnumber" HeaderText="Fnumber" />
                <asp:ButtonField ButtonType="Button" runat="server" CommandName="RowClick" Text="Select"  />
            </Columns>
        </asp:GridView>

    protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Select")
        {
            /* use this format or one below
            int index = Convert.ToInt32(e.CommandArgument);
            GridViewRow selectedRow = GridView2.Rows[index];
            TableCell tcFNumber = selectedRow.Cells[0];
            String Fnumber = tcFNumber.Text;
            */
            DataRowView rowView = (DataRowView)e.Row.DataItem;
            String Fnumber = rowView["Fnumber"].ToString();
        }
    }

Open in new window

0
 
Angela4evaAuthor Commented:
thanks
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now