C# 如何将dropdownlist与标签绑定
我有两个SP,都在做不同的事情,但它们通过ID连接。。。如何绑定这些标签,以便标签随下拉选择而更改C# 如何将dropdownlist与标签绑定,c#,asp.net,label,dropdown,C#,Asp.net,Label,Dropdown,我有两个SP,都在做不同的事情,但它们通过ID连接。。。如何绑定这些标签,以便标签随下拉选择而更改 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Refreshdata(214, DateTime.Today, DateTime.Today.AddDays(1).AddMinutes(-1));
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Refreshdata(214, DateTime.Today, DateTime.Today.AddDays(1).AddMinutes(-1));
BindDropDownList();
LabelCount(214, DateTime.Today, DateTime.Today.AddDays(1).AddMinutes(-1));
}
}
private void BindDropDownList()
{
BizManager mgr = new BizManager();
DataView dv = mgr.GetItemSeriesMaster().DefaultView; //how to filter data
dv.RowFilter = ProductQueryFilter;
Dropdownlist1.DataSource = dv; //datasource == usp.getitemseriesmaster
Dropdownlist1.DataTextField = "Description"; // the items to be displayed in the list items
Dropdownlist1.DataValueField = "Id"; // the id of the items displayed
Dropdownlist1.DataBind();
}
private string ProductQueryFilter
{
get
{
return ConfigurationManager.AppSettings["ProductQueryFilter"];
} //returns itemseriesmaster 214 or 225 from web config key.
}
public void Refreshdata(int selectedProduct, DateTime shiftStart, DateTime shiftEnd)
{
BizManager biz = new BizManager();
GridView1.DataSource = biz.GetPacktstatisticsForShift( //passing in the usp
shiftStart
, shiftEnd
, selectedProduct).DefaultView; //passing in the parameters for the usp
GridView1.DataBind();
}
public void Dropdownlist1_SelectedIndexChanged(object sender, EventArgs e) //this fires after a DDL selection
{
DateTime shiftStart = DateTime.Today; //declaring the param at today - As below
DateTime shiftEnd = DateTime.Today.AddDays(1).AddMinutes(-1);
int productId; //declaring product ID
if (int.TryParse(Dropdownlist1.SelectedValue, out productId))
Refreshdata(productId, shiftStart, shiftEnd);
}
public void LabelCount(int seriesMasterId, DateTime shiftStart, DateTime shiftEnd)
{
{
}
所以,我真的被困在这里,我的标签被放在表单视图中,因为我只需要一条定期更新的记录。我知道bottom方法不是一个表单视图,但我希望在不使用表单视图的情况下可以找到解决方法。但是,即使在搜索了数小时的internet之后,我也看不到任何方法可以做到这一点。您的意思是要根据下拉选择更改页面上的元素,但不刷新页面?我有一个下拉列表,根据下拉选择在gridview中显示不同的数据,标签需要更改以反映下拉列表中选择的更改。。。。dropdownlist和label具有完全相同的参数,即225和214…@danielcarey:如果在更改dropdownlist时需要更改标签,请从
Dropdownlist1\u SelectedIndexChanged
执行此操作。我真的不知道实际的问题是什么。我相信问题来自于is页面的回发部分,因为我正在那里传递一个值,并且在每次回发(30秒)后,它会刷新回输入的值。。。但这不是我想要的。。。每次刷新后,我需要它停留在选中的页面上。。。但是我找不到一种不在refreshData方法中添加defualt值(214)的方法。。。