asp.net - Binding datatable values into a checkbox that's placed inside GridView -
i binding datatable gridview has checkbox in 1 of fields. have trouble getting checkbox checked according datatable.
this have far:
<asp:templatefield headertext="approved" sortexpression="approved"> <itemtemplate> <asp:checkbox id="checkbox1" runat="server" checked='<%# eval("approved").tostring() == "y" ? true : false %>' enabled="false" /> </itemtemplate> <itemstyle horizontalalign="center" /> </asp:templatefield>
code behind:
dim adp sqldataadapter = new sqldataadapter(sqlcmd) dim ds dataset = new dataset() adp.fill(ds, "table_name") dt = new datatable() dt = ds.tables("table_name") gridview1.datasource = dt gridview1.databind()
edit: getting error bc30201: expression expected. on particular line:
<asp:checkbox id="checkbox1" runat="server" checked='<%#eval("approved").tostring() == "y" ? true : false %>' enabled="false" />
edit answer: got work, found out ternary operators not exist in vb.
<asp:checkbox id="checkbox1" runat="server" checked='<%# eval("approved").tostring().toupper().trim() = "y" %>' enabled="false"/>
you code right may not getting check boxes checked because values may saved space @ beginning or @ end need use trim()
method make sure condition satisfies call toupper()
convert database value upper case matches upper case y
.
<asp:checkbox id="checkbox1" runat="server" checked='<%# eval("approved").tostring().toupper().trim() == "y" ? true : false %>' enabled="false" />
Comments
Post a Comment