Click here to Skip to main content
15,901,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am using gridview and there is a column of checkbox so i want to checkbox make true for value that come from database and match with some row data. so what can i do ?

string s = "select document_id,user_id from document_rights where user_id='" +drop_user.SelectedItem.Value + "' and category='" +drop_cat.SelectedItem.Value+ "' and sub_cat='" + drop_sub_cat.SelectedItem.Value + "'";
SqlDataAdapter ad = new SqlDataAdapter(s, c.getcon());
DataSet ds = new DataSet();
ad.Fill(ds);

if (ds.Tables[0].Rows.Count != 0)
{
xxx = ds.Tables[0].Rows[0][0].ToString();
string[] split = xxx.Split(',');
intArray1 = new int[split.Length];
for (int i = 0; i < split.Length; i++)
{
intArray1[i] = System.Convert.ToInt32(split[i]);

}
string xxxx = "select title,id from document where id in(";
for (int k = 0; k < intArray1.Length; k++)
{
xxxx += intArray1[k] + ",";
}
xxxx = xxxx.Substring(0, xxxx.Length - 1) + ") and category='" + drop_cat.SelectedItem.Value + "' and subctgry='" + drop_sub_cat.SelectedItem.Value + "'";
SqlDataAdapter ad1 = new SqlDataAdapter(xxxx, c.getcon());
DataSet ds1 = new DataSet();
ad1.Fill(ds1);

if (ds1.Tables[0].Rows.Count != 0)
{
foreach (GridViewRow di in GridView1.Rows)
{
CheckBox chkBx = (CheckBox)di.FindControl("CheckBox1");


}
}
GridView1.DataSource = c.getdata("select id,title from document where category='" + drop_cat.SelectedItem.Text + "' and subctgry='" + drop_sub_cat.SelectedItem.Text + "'");
GridView1.DataBind();
}
Posted
Updated 24-Apr-12 20:13pm
v2
Comments
hitech_s 25-Apr-12 1:26am    
use rowdatabound event in that check with with the value you want to verify and then make the checkbox value to true(checked)
dineshkanagaraj 25-Apr-12 1:39am    
Use Rounddatabound Event

1 solution

Hi,
I presume you want to make a CheckBox checked based on a value from database, then, you can use something like this:
ASP.NET
<asp:checkbox checked="<%# MakeChecked(Eval("FieldName")) %>" ...="" xmlns:asp="#unknown" />

Then in your code behind:

C#
public bool MakeChecked(object fieldValue)
{
   //Some code to evaluate fieldValue
   //and then based on that return true/false
}


Cheers
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900