Click here to Skip to main content
15,922,325 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,


how to do:
Selected value on a DropDownList inside of a repeater???
Posted
Comments
What have you tried?
abdul subhan mohammed 16-Feb-14 3:39am    
DateTime dt = Convert.ToDateTime(Request.QueryString["VehicleTrackingDate"]);
SqlParameter[] Param = new SqlParameter[1];
Param[0] = new SqlParameter("@DateAsOf", dt);
Repeater1.DataSource = DAL.GetDataWithParameters("Sp_GetVehicleTrackingOnDate", Param);
Repeater1.DataBind();

foreach (RepeaterItem dataItem in Repeater1.Items)
{
((DropDownList)dataItem.FindControl("ddldept")).SelectedValue = true;
}

Try on this Way may Be its can working if not then Write proper that u want to implement

DateTime dt = Convert.ToDateTime(Request.QueryString["VehicleTrackingDate"]);
SqlParameter[] Param = new SqlParameter[1];
Param[0] = new SqlParameter("@DateAsOf", dt);
Repeater1.DataSource = DAL.GetDataWithParameters("Sp_GetVehicleTrackingOnDate", Param);
Repeater1.DataBind();

for (int i=0;i<=Repeter1.Items.Count-1;i++)
{
//((DropDownList)dataItem.FindControl("ddldept")).SelectedValue = true;
DropDownList drp=(DropDownList)Repeater1.Items[i].FindControl("ddldept");
drp.SelectedValue = true;
}

Thanking You!!
 
Share this answer
 
protected void ddlstatus_SelectedIndexChanged(object sender, EventArgs e)
      {
          DropDownList d = (DropDownList)sender;
          int val = Convert.ToInt32(d.SelectedValue);

          int count = Repeater1.Items.Count;
          int index = 0;
          string cID = d.UniqueID;

          while (index < count)
          {
              if (Repeater1.Items[index].ItemType == ListItemType.Item || Repeater1.Items[index].ItemType == ListItemType.AlternatingItem)
              {
                  if (Repeater1.Items[index].FindControl("ddlstatus") != null)
                  {
                      DropDownList ddl = Repeater1.Items[index].FindControl("ddlstatus") as DropDownList;
                      if (ddl.UniqueID == cID)
                      {
                          if (Repeater1.Items[index].FindControl("txtlocation") != null)
                          {
                              TextBox txtLoc = Repeater1.Items[index].FindControl("txtlocation") as TextBox;
                              txtLoc.Text = ((val == 2) ? "Pool" : String.Empty);
                          }
                          if (Repeater1.Items[index].FindControl("ddldept") != null)
                          {
                              DropDownList ddldept = Repeater1.Items[index].FindControl("ddldept") as DropDownList;
                              ddldept.Enabled = ((val == 2) ? false : true);
                          }
                          if (Repeater1.Items[index].FindControl("txtdriver") != null)
                          {
                              TextBox txtLocd = Repeater1.Items[index].FindControl("txtdriver") as TextBox;
                              txtLocd.Enabled = ((val == 2) ? false : true);
                          }
                      }
                  }
              }
              index++;
          }

      }
 
Share this answer
 
C#
protected void myRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item ||
       e.Item.ItemType == ListItemType.AlternatingItem)
    {
        var degree_dropdown = e.Item.FindControl("degree_dropdown") as DropDownList;
        string degreeCode = (string) ((DataRowView) e.Item.DataItem)["degreeCode"];

        if (degree_dropdown != null)
        {
            degree_dropdown.DataSource = degrees; //a datatable
            degree_dropdown.DataTextField = "degree";
            degree_dropdown.DataValueField = "code";
            degree_dropdown.DataBind();

            if (degree_dropdown.Items.FindByValue(degreeCode) != null)
                degree_dropdown.SelectedValue = degreeCode;
        }
    }
}

source here[^]

-KR
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900