在转发器内的DropDownList上的选定值 [英] Selected value on a DropDownList inside of a repeater
本文介绍了在转发器内的DropDownList上的选定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
怎么做:
一个DropDownList中的选定值转发器???
Hi guys,
how to do:
Selected value on a DropDownList inside of a repeater???
推荐答案
尝试这种方式可能是它可以工作如果没有然后写你想要实现的正确
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;
}
感谢你!!
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!!
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++;
}
}
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
这篇关于在转发器内的DropDownList上的选定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文