[英]Drop Down Control Selected Index change event
In my webfrom in asp.net I have a grid view a button, a text box and a Dropdownlist. 在asp.net的webfrom中,我有一个网格视图,一个按钮,一个文本框和一个下拉列表。 I have a method like this to call and select the data in to my grid view. 我有一个这样的方法来调用并选择我的网格视图中的数据。
public void fillGridByAuthor(string searchKey)
{
GVDetails.DataSource = new ViewAllBKByAuthorOP().searchAuthorByAUNM(searchKey);
GVDetails.DataBind();
}
This is my business layer method. 这是我的业务层方法。
public DataTable searchAuthorByAUNM(string searchKey)
{
string query2 = "EXEC SelectBooksDTByAuthor'" + searchKey + "'";
return new DataAccessLayer().executeTable(query2);
}
I'm calling fillGridByAuthor method in form in the drop downlist selected index change event like this. 我在下拉列表中选择索引更改事件的形式中调用fillGridByAuthor方法,就像这样。
protected void DDAuthor_SelectedIndexChanged(object sender, EventArgs e)
{
fillGridByAuthor(DDAuthor.Text);
}
and in the button click event like this 并在按钮单击事件这样
protected void btnSearch_Click(object sender, EventArgs e)
{
fillGridByAuthor(txtAuName.Text);
}
It is working fine when the button is clicked. 单击按钮时工作正常。 Though I select the same Item in the drop down list, it doesn't give me the same output. 虽然我在下拉列表中选择了相同的项目,但它并没有给我相同的输出。 What's incorrect here? 这里有什么不对?
The
Text
property gets and sets the same value that theSelectedValue
property does.Text
属性获取并设置SelectedValue
属性所执行的相同值。 TheSelectedValue
property is commonly used to determine the value of the selected item in theListControl
control.SelectedValue
属性通常用于确定ListControl
控件中所选项的值。 If no item is selected, an empty string ("") is returned. 如果未选择任何项目,则返回空字符串(“”)。
So the Text
property returns the Value
not the Text
property of the currently selected item. 因此Text
属性返回Value
而不是当前所选项的Text
属性。 Use SelectedItem.Text
instead. 请改用SelectedItem.Text
。
fillGridByAuthor(DDAuthor.SelectedItem.Text);
Try adding autopostback = true to your dropdownlist. 尝试将autopostback = true添加到下拉列表中。 It will probably help 它可能会有所帮助
And, you should do this: 而且,你应该这样做:
fillGridByAuthor(DDAuthor.SelectedValue);
EDIT 编辑
what Tim Schmelter is probably better because you want the text so: Tim Schmelter可能更好,因为你想要这样的文字:
fillGridByAuthor(DDAuthor.SelectedItem.Text);
只需将下拉列表的AutoPostBack属性设置为true,它就像魅力一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.