我有一个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"的值,两个值都是空的。。。。。。。请帮忙。。。。。。。。。。
你可以试试这个吗?
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属性中查看/检查此变量的内容:
-文本:是刚刚选择的项目的文本。
-值:是刚刚选择的项目的值。
-OldText:是以前选择的项目的文本
-OldValue:是以前选择的项目的值
或者试试这个:
Label1.Text = "You selected " + SelectInitiative.SelectedValue + " item";
我也遇到了类似的问题,对我来说,问题的根源是我在每个AutoPostBack上都设置了数据源。请确保在事件触发之前没有重新初始化组合框中的项目。