Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
150
WebDataTree Checkbox not checked after databind
posted

Want to have the checkbox be checked (or not) depending on bound data.  Am unable to get it to do so.  Very simple test code. (sorry for state of what follows; have tried to edit it repeatedly to 'nice it up'..  editor s**ks!)

 .axpx
<ig:WebDataTree ID="WebDataTree1" runat="server" CheckBoxMode="biState">
<DataBindings>
  <ig:DataTreeNodeBinding DataMember="tb1" KeyField="Id" TextField="Name" ValueField="CheckValue" />
</DataBindings>
</ig:WebDataTree>

.aspx.cs
public partial class TestWebDataTree : System.Web.UI.Page
{protected void Page_Load(object sender, EventArgs e){
  
DataSet ds = GetData();
   WebDataTree1.DataSource = ds;
   WebDataTree1.DataBind();}
protected DataSet GetData(){
  
DataSet ds = new DataSet("ds1");
  
DataTable dt = new DataTable("tb1");
   dt.Columns.Add(
"Id", System.Type.GetType("System.Int32"));
   dt.Columns.Add(
"Name", System.Type.GetType("System.String"));
   dt.Columns.Add(
"CheckValue", System.Type.GetType("System.Int16"));
  
DataRow dr;
  
dr = dt.NewRow();
   dr[
"Id"] = 1; dr["Name"] = "One"; dr["CheckValue"] = Infragistics.Web.UI.CheckBoxState.Checked; 
   dt.Rows.Add(dr);
   ds.Tables.Add(dt);
return ds;}}

I expect 1 row with "One" as the text and the checkbox checked. Text = "One", but checkbox is not checked. Please help.

P.S. Is there a way to do this with a Template and a %@Eval()% ?

Thx
Parents
No Data
Reply
  • 49378
    posted

    Hi contibeef,

    Thank you for posting in the community.

    You will need to set the checkbox state of each item in your WebDataTree after the data has been bound. This can be done in the DataBound event handler using the following code (developed using the dataset you have provided):

        protected void WebDataTree1_DataBound(object sender, EventArgs e)
        {
            foreach (DataTreeNode node in WebDataTree1.AllNodes)
            {
                var isItemChecked =  Int16.Parse((((System.Data.DataRowView)(((Infragistics.Web.UI.Framework.Data.DataSetNode)(node.DataItem)).Item)).Row.ItemArray[2]).ToString());
                node.CheckState = (CheckBoxState) isItemChecked;
            }
        }

    Please let me know if this helps.

     

Children