在我的 asp.net webfrom 中,我有一个 GridView 、一个按钮、一个文本框和一个下拉列表。 我有一个类似这样的方法来调用数据并将其选择到我的 GridView 中。
public void fillGridByAuthor(string searchKey)
{
GVDetails.DataSource = new ViewAllBKByAuthorOP().searchAuthorByAUNM(searchKey);
GVDetails.DataBind();
}
这是我的业务层方法。
public DataTable searchAuthorByAUNM(string searchKey)
{
string query2 = "EXEC SelectBooksDTByAuthor'" + searchKey + "'";
return new DataAccessLayer().executeTable(query2);
}
我在下拉列表选择的索引更改事件中调用表单中的 fillGridByAuthor 方法,就像这样。
protected void DDAuthor_SelectedIndexChanged(object sender, EventArgs e)
{
fillGridByAuthor(DDAuthor.Text);
}
在这样的按钮点击事件中
protected void btnSearch_Click(object sender, EventArgs e)
{
fillGridByAuthor(txtAuName.Text);
}
单击按钮时它工作正常。虽然我在下拉列表中选择了相同的项目,但它并没有给我相同的输出。 这里有什么不正确的?
最佳答案
来自 MSDN :
The
Text
property gets and sets the same value that theSelectedValue
property does. TheSelectedValue
property is commonly used to determine the value of the selected item in theListControl
control. If no item is selected, an empty string ("") is returned.
因此 Text
属性返回的是 Value
而不是当前所选项目的 Text
属性。请改用 SelectedItem.Text
。
fillGridByAuthor(DDAuthor.SelectedItem.Text);
关于c# - 下拉控件选中的索引更改事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26480488/