0

In this I have added one DropDownList in the Repeater control, For that one DataTable is assigned as the DataSource.

But I want to edit the DropDownList.Items as per the DataSource data.

Means if the DataSource will give the 3 data then the DropDownLidt has the list items from 1,2,3 if that is 5 then 1,2,3,4,5 like this

So for that which Event I have to use and what code I should write?

abatishchev
  • 92,232
  • 78
  • 284
  • 421

2 Answers2

0

In your itemdatabound of your Repeater, find your control, and bind to a database, or set values, or whatever you want as shown below:

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView row = e.Item.DataItem as DataRowView;

                DropDownList dl = e.Item.FindControl("ddlCategory") as DropDownList;
                dl.DataSource = CategoriesDataTable;
                dl.DataTextField = "CategoryDescription";
                dl.DataValueField = "CategoryPK";
                dl.SelectedValue = row["CategoryFK"].ToString();
                dl.DataBind();
            }
Akhil
  • 7,310
  • 1
  • 22
  • 22
0
 protected void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            int count = 0;
            // set count = your datatable count 
            DropDownList ddl = (DropDownList)e.Item.FindControl("ddl");  
            for(int i=1;i<=count;i++)
            {
                ddl.Items.Add(i.ToString());    
            }

        }
    }
Saurabh
  • 5,523
  • 2
  • 22
  • 32