radcombobox中的selectedindexchanged事件

时间:2013-02-25 08:50:04

标签: combobox selectedindex rad-controls radcombobox

我有一个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”的值,两个值都是空的.......请帮助........ ..

2 个答案:

答案 0 :(得分: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";

答案 1 :(得分:0)

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