brain has stalled datagrid checkboxlist

C

cindy

I am using asp template columns. I display box values from a lookup table.
The datagrid displays field "bookid" and the checkbox displays "category"
field for the book. The category field is a string concatenation of category
values such as CT,MR,NM or just CT
When the grid goes into edit mode I use the itemdatabound to determine
whether to set checkbox as selected based on the value of the category field.
((CheckBoxList)e.Item.Cells[0].FindControl("cbl1")).SelectedValue =
ds.Tables[0].Rows[cnt]["Category"].ToString();
Ok if category = CT How do I get an array into the itemdatabound with comma
delimiter so CT,MR for example will see values as CT and a MR:
The update command for the grid builds the string by looping thru the
selected values from the checkbox. Am I completely missing a better way?
 
P

Phillip Williams

string strCategory = "CT,MR";
CheckBoxList cbl1= (CheckBoxList)e.Item.Cells[0].FindControl("cbl1");
string[] aCategories= strCategory.Split (',');
foreach (string str in aCategories)
{
System.Web.UI.WebControls.ListItem li= cbl1.Items.FindByValue (str);
if (li != null) li.Selected =true ;
}
 
C

cindy

Thank you very much, I had just stalled and you replied so quickly.
--
cindy


Phillip Williams said:
string strCategory = "CT,MR";
CheckBoxList cbl1= (CheckBoxList)e.Item.Cells[0].FindControl("cbl1");
string[] aCategories= strCategory.Split (',');
foreach (string str in aCategories)
{
System.Web.UI.WebControls.ListItem li= cbl1.Items.FindByValue (str);
if (li != null) li.Selected =true ;
}
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


cindy said:
I am using asp template columns. I display box values from a lookup table.
The datagrid displays field "bookid" and the checkbox displays "category"
field for the book. The category field is a string concatenation of category
values such as CT,MR,NM or just CT
When the grid goes into edit mode I use the itemdatabound to determine
whether to set checkbox as selected based on the value of the category field.
((CheckBoxList)e.Item.Cells[0].FindControl("cbl1")).SelectedValue =
ds.Tables[0].Rows[cnt]["Category"].ToString();
Ok if category = CT How do I get an array into the itemdatabound with comma
delimiter so CT,MR for example will see values as CT and a MR:
The update command for the grid builds the string by looping thru the
selected values from the checkbox. Am I completely missing a better way?
--
cindy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top