Reputation: 269
my question is very simple. here is my scenario:
The data inside dataTable will be:
Column1 | Column2 | Column3
Method1 | 100 | 0.5
Method2 | 125 | 0.75
Method3 | 80 | 0.4
. . .
Method30 | 200 | 1
currently, i used the simplest way for binding data. something like:
ddl1.SelectedValue = ((MyDataSet.MyDTRow)resultDS.MyDT.Rows[0]).Column1;
ddl2.SelectedValue = ((MyDataSet.MyDTRow)resultDS.MyDT.Rows[0]).Column2;
ddl3.SelectedValue = ((MyDataSet.MyDTRow)resultDS.MyDT.Rows[0]).Column3;
ddl4.SelectedValue = ((MyDataSet.MyDTRow)resultDS.MyDT.Rows[1]).Column1;
ddl5.SelectedValue = ((MyDataSet.MyDTRow)resultDS.MyDT.Rows[1]).Column2;
ddl6.SelectedValue = ((MyDataSet.MyDTRow)resultDS.MyDT.Rows[1]).Column3;
.
.
.
ddl30.SelectedValue = ((MyDataSet.MyDTRow)resultDS.MyDT.Rows[9]).Column3;
Is there any way to bind data to my ddl easier than my current method?
Thank you.
vcha
Upvotes: 0
Views: 143
Reputation: 1562
I would set this up in a Databound control Like a ListView
or GridView
.
This will allow you to Create the 3 ddls that will be repeated then bind the SelectedItemValue
to your column.
I am making some assumptions based on what you have shown that this will work for you. If the ddls are scattered throughout the site then it may not.
Upvotes: 0
Reputation: 108957
Assuming the last line in you code has Rows[9]
You can try doing it in a loop
for (int i=0; i<30; i++)
{
DropDownList ddl = (DropDownList) FindControl("ddl"+(i+1));
switch (i % 3)
{
case 0:
ddl.SelectedValue = ((MyDataSet.MyDTRow)resultDS.MyDT.Rows[i/3]).Column1;
break;
case 1:
ddl.SelectedValue = ((MyDataSet.MyDTRow)resultDS.MyDT.Rows[i/3]).Column2;
break;
case 2:
ddl.SelectedValue = ((MyDataSet.MyDTRow)resultDS.MyDT.Rows[i/3]).Column3;
break;
}
}
Upvotes: 1