CheckBoxes in DataGrid

  • Thread starter Thread starter drakuu
  • Start date Start date
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
 
hello dra...,
try this,

best regards,
<asp:TemplateField>
<EditItemTemplate>
<asp:CheckBox ID="CheckBoxU" runat="server"
Checked = '<%# Databinder.Eval(Container.DataItem,
""AddressTypeCode").ToString() == "u"%' />
</EditItemTemplate>
</asp:TemplateField>


or you can do a method that accepts the datarow view and return the
bool value. This is reccomened for complex expressions.

rodel e. dagumampan
filipino developer c#/asp.net/winforms
http://community.devpinoy.org/blogs/dehranph
 
Back
Top