Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
1.40/5 (2 votes)
See more:
I want to find a linkbutton which is inside in gridview , when i click on a button that time i want linkbutton text. click button is outside of gridview
Posted
Comments
Gihan Liyanage 23-Sep-14 6:58am    
Not Clear dude..
sureshsharma123 23-Sep-14 8:02am    
hii sir
i want to update gridview controls values on button click, and button is not in gridview means outside of gridview on a form

1 solution

Hi dude you can do this in two ways

1)RowCommand
2)Button Click event

RowCommand:

<asp:gridview id="gridMembersList" xmlns:asp="#unknown">
AutoGenerateColumns="False" GridLines="None" 
            runat="server"  
            onrowcommand="gridMembersList_RowCommand">
        <columns>
        <asp:templatefield headertext="User Name">
        <itemtemplate>
            <asp:literal id="ltrlName" runat="server">
            Text='<%# Eval("Name") %>'></asp:literal>
            <asp:literal id="ltrlSlno" runat="server" visible="False">
                Text='<%# Eval("Id") %>'></asp:literal>
        </itemtemplate>
        </asp:templatefield>
        
        <asp:templatefield headertext="View More">
        <itemtemplate>
            <asp:button id="btnViewmore">
            CommandArgument="<%# ((GridViewRow) Container).RowIndex %>
            " CommandName="More" runat="server" Text="View More" />
        </asp:button></itemtemplate>
        </asp:templatefield> 
        </columns>
        </asp:gridview>  



protected void gridMembersList_RowCommand(object sender, GridViewCommandEventArgs e)
  {
       if (e.CommandName == "More")
       {
           int index = Convert.ToInt32(e.CommandArgument.ToString());
           Literal ltrlslno = (Literal)gridMembersList.Rows[index].FindControl("ltrlSlno");
           Literal ltrlName = (Literal)gridMembersList.Rows[index].FindControl("ltrlName");
           ScriptManager.RegisterStartupScript(this, this.GetType(),
           "Message", "alert('" + ltrlName.Text+ "');", true);
       }
   }



Button Click event


XML
<asp:GridView AutoGenerateColumns="false" runat="server" ID="grdCustomPagging">
   <Columns>
       <asp:BoundField DataField="RowNumber" HeaderText="RowNumber" />
       <asp:BoundField DataField="DealId" HeaderText="DealID" />
       <asp:BoundField DataField="Dealtitle" HeaderText="DealTitle" />
       <asp:TemplateField HeaderText="View">
        <ItemTemplate>
       <asp:LinkButton runat="server" ID="lnkView" OnClick="lnkView_Click">View Deal</asp:LinkButton>
         </ItemTemplate>
       </asp:TemplateField>
   </Columns>
</asp:GridView>

protected void lnkView_Click(object sender, EventArgs e)
{
    GridViewRow grdrow = (GridViewRow)((LinkButton)sender).NamingContainer;
    string rowNumber = grdrow.Cells[0].Text;
    string dealId = grdrow.Cells[1].Text;
    string dealTitle = grdrow.Cells[2].Text;
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900