Hi Please check below code ..
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DataGrid.aspx.cs" Inherits="DataGrid" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:DataGrid ID="DataGrid1" runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:BoundColumn DataField="Name" HeaderText="Name"></asp:BoundColumn>
<asp:BoundColumn DataField="password" HeaderText="Password"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True"
oncheckedchanged="CheckBox1_CheckedChanged" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class DataGrid : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
try
{
string Connection = "data source=WS-INBLR131\\SQLEXPRESS;initial catalog=Practive;integrated security=true";
SqlConnection _con = new SqlConnection(Connection);
SqlCommand cmd = new SqlCommand("select * from User_details", _con);
cmd.Parameters.AddWithValue("@name", "murali");
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DataGrid1.DataSource = ds;
DataGrid1.DataBind();
}
catch (Exception ex)
{
ex.Message.ToString();
}
}
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
//write code what you want..
}
}
Best Regards
Murali Krishna.S
Sreekanthv5, if this helps please login to Mark As Answer. | Alert Moderator