how to add a button in griedview and fire its click event

Posted by Shanky11 under ASP.NET on 9/29/2012 | Points: 10 | Views : 1040 | Status : [Member] | Replies : 2
i hav a Griedview Autogenreate column=false; i have taken a panel inside this gridview and a table inside a panel in that i have a label
Demo Of Query Not Actual DEsign
<asp:gridview> auto genrete columns =false;
<panel>
<table>
<tr><td>Label </td> <tr>////////////i have to find this label id?????????
</asp:gridview>
Query:Now I Have To Find Id Of That Label?????????????????????????????????????




Responses

Posted by: Solijoseph on: 9/29/2012 [Member] Starter | Points: 25

Up
0
Down
Use DataList Instead of Datagrid For your requirement

Thanks & Regards
Solimon Joseph

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sureshknkt7 on: 10/3/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

this will help you,

this is aspx code:

<asp:GridView ID="Gridview1" runat="server" AutoGenerateColumns="false">

<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Panel ID="panel1" runat="server">
<table>
<tr>
<asp:Label ID="lblData" runat="server" Text='<%#Eval("UserName") %>'></asp:Label>
</tr>
<tr>
<td>
<asp:Label ID="lblSample" runat="server"></asp:Label>
</td>
</tr>
</table>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>



In the code Behind, Page_Load Event
Bind the data from database to the Gridview



DataTable table = new DataTable();

using (SqlConnection con = new SqlConnection(_connStr))
{
string sqlquery = "select *from Login";
using (SqlCommand cmd = new SqlCommand(sqlquery, con))
{
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(table);
}
Gridview1.DataSource = table;
Gridview1.DataBind();
}



In the Button Click Event write following code
to find the Label id.

protected void Check_Label(object sender, EventArgs e)

{
foreach (GridViewRow row in Gridview1.Rows)
{
Label lbllblSample1 = (Label)row.FindControl("lblSample");
lbllblSample1.Text = "Hi Here is Lable Text";
}
}


Thanks

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response