Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > how to check/Uncheck a checkbox dynamically in a datagrid in asp.net

Reply
Thread Tools

how to check/Uncheck a checkbox dynamically in a datagrid in asp.net

 
 
Neal
Guest
Posts: n/a
 
      04-27-2005
HI all,

I have an issue with check box in datagrid.
I would like it to check and uncheck based on a database value of NULL
or a Date Value.

If there is a date value for that column then check the check box in
datagrid

If the value is null then keep it unchanged as (Unchecked)

this is in asp.net

Your help is appreciated

Thank you

Neal

 
Reply With Quote
 
 
 
 
surindersaini@gmail.com
Guest
Posts: n/a
 
      04-27-2005
hi,

Datagrid code with check box and date field

<aspataGrid id="grdAuthors" runat="server" Width="626px">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="chkbox" Runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="Date" HeaderText="Date"
></asp:BoundColumn>

</Columns>
</aspataGrid>

and with dataItemBound event of grid u can write code as below


string _lblDate = e.Item.Cells[1].Text.ToString(); //date column
CheckBox _chkBox = (CheckBox)e.Item.FindControl("chkbox");
if(_chkBox != null)
{
if(_lblDate == "True")//Here u can check if some date text is
//bound with the label
{
_chkBox.Checked = true;
}
}

 
Reply With Quote
 
 
 
 
subashini subashini is offline
Junior Member
Join Date: Mar 2012
Posts: 6
 
      03-05-2012

Hi,

Try this... it vl help u.
i used gridview.
got the id of the student.
as the userid is in a datalist. so i too from ther.
check the active status from a table.
i used checkboxes. if the user is in an active status then boxes should be checked.
protected void dgGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow ||
e.Row.RowType == DataControlRowType.Separator)
{
Label lblstudentname = (Label)e.Row.FindControl("lblstudentname");
string studentname = lblstudentname.Text.Trim();
Label lbluserid = (Label)e.Row.FindControl("lbluserid");
string userid = lbluserid.Text.Trim();
DataSet ds1 = comProfile.getAssessmentChar();
DataList dldata = (DataList)e.Row.FindControl("dldata");
for (int i = 0; i < dldata.Items.Count; i++)
{
Label lblid1 = (Label)dldata.Items[i].FindControl("lblid1");
string lsid = lblid1.Text.Trim();
int lsid1 = Convert.ToInt32(lsid);
CheckBox chkactive = (CheckBox)dldata.Items[i].FindControl("chk1");
DataSet ds = comProfile.getDetails(userid, iyear, lsid);

if(ds.Tables[0].Rows.Count > 0)
chkactive.Checked = true;
else
chkactive.Checked = false;
}
}
}

Regards
suba


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGrid and embeded Checkbox..How to find if checkbox clicked =?Utf-8?B?RG90TmV0RGV2?= ASP .Net 1 10-06-2006 04:11 PM
Create the checkbox template column dynamically in datagrid NEMA ASP .Net 0 06-05-2006 02:44 PM
Howto bind CheckBox to the datagrid/ Then update the database field when the checkbox is clicked. Joey Pang ASP .Net Datagrid Control 4 06-13-2005 02:29 AM
how to check/Uncheck a checkbox dynamically in a datagrid in asp.n =?Utf-8?B?U2lsZWVzaA==?= ASP .Net 4 12-02-2004 03:25 PM
how to add checkbox in DataGrid control dynamically? J Gopinath ASP .Net Web Controls 0 06-01-2004 09:45 AM



Advertisments