Hi @eshant.kapoor.5
You can do it like this.
HTML
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White">
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True"
oncheckedchanged="CheckBox1_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Id" HeaderText="Id" ItemStyle-Width="30">
<ItemStyle Width="30px" />
</asp:BoundField>
<asp:BoundField DataField="comp_name" HeaderText="Company Name"
ItemStyle-Width="100">
<ItemStyle Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="Country" HeaderText="Country" ItemStyle-Width="100">
<ItemStyle Width="100px" />
</asp:BoundField>
</Columns>
<HeaderStyle BackColor="#3AC0F2" ForeColor="White" />
</asp:GridView>
</div>
Namespace
using System.Data;
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)),
new DataColumn("comp_name", typeof(string)),
new DataColumn("Country",typeof(string)) });
dt.Rows.Add(1, "TCS", "India");
dt.Rows.Add(2, "McDonald", "USA");
dt.Rows.Add(3, "Alibaba", "China");
dt.Rows.Add(4, "Pizza Ht", "USA");
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
CheckBox chk = (CheckBox)sender;
if (chk.Checked == true)
{
GridViewRow gvr = (GridViewRow)chk.NamingContainer;
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Id = " + GridView1.Rows[gvr.RowIndex].Cells[1].Text + ", Company Name = " + GridView1.Rows[gvr.RowIndex].Cells[2].Text + ", Country = " + GridView1.Rows[gvr.RowIndex].Cells[3].Text + "')", true);
}
}