1

i am trying to design a gridview with linkbuttons.

Below is gridview that I want it to be, ID, Name and Status are Label, Click1 and Click 2 are LinkButtons

ID ------------- Name ------------- Status ------------- Click1-----Click2 

1 -------------- Name1 ------------ Active ------------ Lnk1--------Lnk2

2 -------------- Name2 ------------ In-active --------- Lnk11-------Lnk22

what i am trying is to change the LinkButton cell text(Lnk1 to 'View') on gridview bind. and on likbutton click i want the text as same on gridview bind(i.e Lnk1) and the same with second linkButton..

thank you....

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
thiru
  • 173
  • 1
  • 4
  • 16

1 Answers1

0

Hope this helps

Mark Up

 <asp:GridView ID="GridView1"
                        OnRowDataBound="GridView1_RowDataBound"
                        AutoGenerateColumns="False"
                        runat="server">
                        <Columns>
                            <asp:BoundField DataField="id" HeaderText="Id"
                                SortExpression="id" />
                            <asp:TemplateField HeaderText="Name" SortExpression="Name">
                                <ItemTemplate>
                                    <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">LinkButton</asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>

Code Behind

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if(e.Row.RowType == DataControlRowType.DataRow)
            {
              LinkButton lbtn =  (LinkButton) e.Row.FindControl("LinkButton1");
                lbtn.Text = "View";
            }
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
          LinkButton  lbtnClick = sender as LinkButton;
            lbtnClick.Text = "lnk1";
        }
Srinu A
  • 21
  • 2
  • 11