1

我有一个 radcombobox:

<telerik:RadComboBox ID="SelectInitiative" runat="server" AutoPostBack="true" 
                    DataSourceID="SqlInitiative" DataTextField="Initiative_Name" 
                    DataValueField="ID"  EmptyMessage="Select Initiative" Height="200px" 
                      OnSelectedIndexChanged="SelectInitiative_SelectedIndexChanged" Width="300px">
                </telerik:RadComboBox></td>
            <td>
                <asp:Label ID="Label1" runat="server" Text=""></asp:Label>

            </td>`


<asp:SqlDataSource ID="SqlInitiative" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ProjectPlanningConnectionString %>" 
        SelectCommand="SELECT * FROM [Initiative]"></asp:SqlDataSource>

该事件的代码如下:

 protected void SelectInitiative_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        if (SelectInitiative.SelectedValue.ToString() != "")
        {
            Session["InitiativeID"] = SelectInitiative.SelectedValue.ToString();
        }
        Label1.Text = "You selected " + e.Value + " item";

    }

问题是它既没有拾取“selectedvalue”或“e.Value”的值,两个值都是空的......请帮助......

4

2 回答 2

0

你可以试试这个吗?

protected void SelectInitiative_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
    if(!IsPostBack)
    {
        if (SelectInitiative.SelectedValue.ToString() != "")
        {
            Session["InitiativeID"] = SelectInitiative.SelectedValue.ToString();
        }
        //Or change this line 
        //Label1.Text = "You selected " + e.Value + " item";
        //To this sample
        Label1.Text = "You selected " + SelectInitiative.SelectedValue + " item";

    }

}

或者从 RadComboBoxSelectedIndexChangedEventArgs 属性中查看/检查此变量的内容:

-Text :是刚刚选择的项目的文本。

-Value :是刚刚选择的项目的值。

-OldText :是先前选择的项目的文本

-OldValue :是先前选择的项目的值

或者试试这个:

Label1.Text = "You selected " + SelectInitiative.SelectedValue + " item";
于 2013-02-25T09:04:09.247 回答
0

我有一个类似的问题,对我来说,来源是我在每个 AutoPostBack 上设置数据源。确保在事件触发之前您没有重新初始化组合框中的项目。

于 2021-05-19T12:07:33.963 回答