【发布时间】:2018-10-08 02:28:46
【问题描述】:
我的网格视图中有一个标题 DDL,由于某种原因,它不会保留我选择的值,而是将网格视图和标题绑定回“起始位置”
在我的 Priority 的 DDL 标头中,我选择了值 '99',但之后我的标头返回到我的 ListItem 的起始位置(即优先级)
<HeaderTemplate>
<asp:DropDownList ID="ddlPriorityHeader" AutoPostBack="True" AppendDataBoundItems="True" OnSelectedIndexChanged="ddlHeader_SelectedIndexChanged" runat="server">
<asp:ListItem>Priority</asp:ListItem>
</asp:DropDownList>
</HeaderTemplate>
我有一个 RowDatabound 用于 gridview,但我什么也不做,然后找到标题的 DDL,然后绑定 DDL。
protected void gwActivity_RowDataBound(object sender, GridViewRowEventArgs e)
{
//.............. some code.....//
string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("SELECT DISTINCT [Priority] FROM [BI_Planning].[dbo].[tblPriority]", con);
con.Open();
ddlPriority.DataSource = cmd.ExecuteReader();
ddlPriority.DataTextField = "Priority";
ddlPriority.DataBind();
}
}
我已将我的gridview 放入一个方法中:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridviewActivity();
}
}
难道我每次都在为我的 gridview 绑定我的 DDL 吗?我被困在这里....
【问题讨论】:
-
为什么要在每个 rowDataBound 上绑定 DDL?只绑定一次。
-
我不明白你的意思?你的意思是为什么我将我的 DDL 绑定在 gwActivity_RowDataBound()... 那么嗯,如何只为我的 DDL 做呢?
-
我应该为每个 DDL 创建一个 RowDataBound 吗?
标签: c# asp.net gridview postback rowdatabound