TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Make CheckBox ReadOnly in ASP.NET
Shridhar Sharma
Aug 10
2015
Code
6.3
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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#