Thursday, December 12, 2024

DropBox with image | Stackoverflow.com | dynamically add attribute code behind

 With setting a fixed value to the newly added attribute, you will assign that value to each item. In order to assign the corresponding value to each item's attribute, you should loop trough the DataRows of the DataTable(dt1). Please consider the following approach so you could achieve the desired functionality.

foreach (DataRow dataRow in dt1.Rows)
      {
          RadComboBoxItem item = new RadComboBoxItem();
 
          item.Text = (string)dataRow["Name"];
          item.Value = dataRow["Id"].ToString();
 
          decimal testValue = (decimal)dataRow["Test"];
 
 
          item.Attributes.Add("Test", testValue.ToString());
          RadComboBox1.Items.Add(item);
 
          item.DataBind();
      }

No comments:

Post a Comment