CheckBoxes in DataGrid

D

drakuu

Hi guys,

I created DataGrid with few checkboxes. I want to bind the checkboxes
and check them if they match a string in a database. An if statement
would look something like this:
if (dataRowChb["AddressTypeCode"].ToString() == "u") checkbox1.checked
= true

Now how would I do it in datagrid using TemplateField:
<asp:TemplateField>
<EditItemTemplate>
<asp:CheckBox ID="CheckBoxU" runat="server" />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBoxU" runat="server"
Text='<%# Eval("AddressTypeCode") %>' />
</ItemTemplate>
</asp:TemplateField>

I'll have 5 checkboxes each for unique character (u, a, c...) and if
there exist AddressId with that AddressTypeCode the check box should be
checked.

Thanks,
draku
 
G

Guest

I think something like that might be what you're looking for:
<asp:CheckBox ID="CheckBoxU" runat="server" Text='<%#
Eval("AddressTypeCode") %>' Checked='<%# Eval("AddressTypeCode") == "u" #>'
/>
Hope this helps.
 
D

dehranph

hello dra,

the best that you can do for complex expression evaludation is to
create a method to evaluate the expression and reutrn a bool value.

[yourpage.aspx.cs]
....
protected bool Evaluate(string value){
boo result = false;
//serries of IF os SWITCH statements
return result;
}
...

[yourpage.aspx]
...
<asp:CheckBox ID="" runat="server" Checked='<%#
Evaluate((Container.DataItem as
DataRowView["AddressTypeCode"].ToString() )%>'
/>
...
best ragrds,

rodel e. dagumampan
filipino developer
http://community.devpinoy.org/blogs/dehranph
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top