?
Solved

Getting gridview column value in button click

Posted on 2010-01-09
3
Medium Priority
?
621 Views
Last Modified: 2012-05-08
<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
Comment
Question by:Angela4eva
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 22

Expert Comment

by:Mrunal
ID: 26276007
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
 
LVL 58

Accepted Solution

by:
HainKurt earned 2000 total points
ID: 26276031
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
 

Author Closing Comment

by:Angela4eva
ID: 31675097
thanks
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question