[英]Display dropdownlist selection with a label
I am having a heck of a time all I want is this. 我有一点时间我想要的就是这个。
label.text = dropdownlist.text label.text = dropdownlist.text
How do I do that with a dropdownlist that is populated with a datasource in the visual studio designer? 如何使用Visual Studio设计器中填充了数据源的下拉列表来完成此操作?
I have an update statement that gets a parameter value from dropdownlist.text, why can't I just set the text property of the label the same way? 我有一个从dropdownlist.text获取参数值的更新语句,为什么我不能以同样的方式设置标签的text属性? I think I am missing something really simple but I can't find it.
我想我错过了一些非常简单但我找不到的东西。
<asp:DropDownList ID="ddlEditFruit" style="Z-INDEX: 159;
LEFT:780px; POSITION: absolute; TOP: 280px;"
runat="server" DataSourceID="update"
DataTextField="fruit_id" DataValueField="fruit_id"
AppendDataBoundItems="True" AutoPostBack="True">
<asp:ListItem Selected ="True" Text="" Value ="">(Select)</asp:ListItem>
</asp:DropDownList>
private void btnUpdate_Click(object sender, System.EventArgs e)
{
if (bxStarch.Text.Trim().Length == 0)
{
this.lblError.Visible = true;
}
else
{
this.lblError.Visible = false;
//string id = ddlEditFruit.SelectedValue.ToString();
this.lblId.Visible = true;
this.lblId.Text = ddlEditFruit.SelectedItem.Text;
edit_fruit();
reset_dropdowns();
resest_dropdowns_2();
fill_grd_fruit_id();
fill_grd_size();
fill_grd_progress();
SetFocus(ddlGrade);
change_back();
}
}
in your codebehind, try this: 在你的代码隐藏中,试试这个:
label.Text = dropdownlist.SelectedItem.Text
SelectedItem
will put the label text to some text, for instance "John" SelectedItem
会将标签文本放到某些文本中,例如“John”
SelectedValue
will put the label text to some value, for instance "5". SelectedValue
会将标签文本设置为某个值,例如“5”。
您可以尝试使用DropDownList
的SelectedValue
:
label.Text = dropdownlist.SelectedValue;
label.Text = dropdownlist.SelectedValue
会这样做:)
I fixed it myself. 我自己修好了。 I was trying to change the label value in the wrong click event.
我试图在错误的点击事件中更改标签值。 Silly error.
愚蠢的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.