简体   繁体   English

使用标签显示下拉列表选择

[英]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”。

您可以尝试使用DropDownListSelectedValue

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.

相关问题 如何在我的视图中显示与DropDownList中的选择相对应的文件夹? - How to display in my view the folders corresponding to my selection in a DropDownList? 如何基于剃须刀中的下拉列表选择动态显示记录 - How to display records dynamically based on dropdownlist selection in razor 如何基于三个下拉列表的选择显示网格视图 - How to display grid view based on the selection of three dropdownlist 如何从DropDownList选择更改文本框中的数据显示? - How to change data display in a TextBox from a DropDownList selection? 在C#中,如何使用标签控件在dropdownlist中显示字符串数组? - in c#, how to display array of string in dropdownlist using label control? 显示下拉列表 - Display DropDownList 如何在Asp.net中使用Javascript根据DropDownlist中的数据选择设置标签文本属性 - How to set Label Text property based on data selection from DropDownlist using Javascript in Asp.net mvc上的DropDownList过滤了卡片/盒子的显示,但是我无法显示所有已加载或默认选择的卡片 - DropDownList on mvc filters a display of cards/boxes, but I can't display all the cards on load or with default selection DropDownList选择和表结构 - DropDownList Selection and table structure 下拉列表中的剃刀默认选择? - Razor default selection in dropdownlist?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM