C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Make CheckBox ReadOnly in ASP.NET
WhatsApp
Shridhar Sharma
Aug 10
2015
7
k
0
0
SetCheckBoxValue.rar
using
System;
using
System.Collections.Generic;
using
System.Data;
using
System.Data.SqlClient;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Configuration;
public
partial
class
AttributesProperty: System.Web.UI.Page {
SqlConnection con =
new
SqlConnection(ConfigurationManager.ConnectionStrings[
"constring"
].ConnectionString);
protected
void
Page_Load(
object
sender, EventArgs e) {
if
(!IsPostBack ==
true
) {
BindData();
}
}
protected
void
BindData() {
try
{
string
strQuery =
"select ID, Attributes, Properties from tblAttributes"
;
SqlCommand cmd =
new
SqlCommand(strQuery, con);
cmd.CommandType = CommandType.Text;
SqlDataAdapter da =
new
SqlDataAdapter(cmd);
DataTable dt =
new
DataTable();
da.Fill(dt);
AttributeGrid.DataSource = dt;
AttributeGrid.DataBind();
}
catch
(Exception ex) {
//throw ex;
}
finally
{
con.Close();
}
}
protected
void
checkProperties_CheckedChanged(
object
sender, EventArgs e) {
CheckBox check = (CheckBox) AttributeGrid.FindControl(
"checkAttributes"
);
GridViewRow GrdRW = (GridViewRow) check.Parent.Parent;
Response.Write(AttributeGrid.DataKeys[GrdRW.RowIndex].Value.ToString());
if
(check.Checked ==
true
) {}
}
protected
void
AttributeGrid_RowDataBound(
object
sender, GridViewRowEventArgs e) {
//
{
if
(e.Row.RowType == DataControlRowType.DataRow) {
//Label a = (Label)DataBinder.Eval(e.Row.DataItem, "lblDept1");
var a = (Label) e.Row.FindControl(
"lblDept1"
);
string
b = a.Text;
if
(b ==
"0"
) {
((CheckBox) e.Row.FindControl(
"checkProperties"
)).Checked =
true
;
}
else
if
(b ==
"1"
) {
((CheckBox) e.Row.FindControl(
"checkProperties"
)).Checked =
false
;
}
else
Response.Write(
"inavlid entry"
);
}
}
}
}
Checkbox
GridView
C#
Up Next
Make CheckBox ReadOnly in ASP.NET