有一次,我可以从网格视图中的静态DDL中进行选择,然后根据我所做的选择更新网格视图。在某些时候,这停止了工作,我无法复活它。
下面是(简化的)代码,其中一切正常除了从DDL获取所选值 - 它总是返回第一个列表项。我知道哪里出错了?
protected void gv_Pending_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit)
{
((DropDownList)e.Row.FindControl("ddl_Pending")).Enabled = true;
}
}
protected void gv_Pending_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int index = Convert.ToInt32(e.RowIndex);
GridViewRow row = gv_Pending.Rows[index];
string adm_appr = ((DropDownList)row.FindControl("ddl_Pending")).SelectedValue.ToString();
}
<asp:GridView ID="gv_Pending" runat="server"
OnRowDataBound="gv_Pending_RowDataBound" OnRowUpdating="gv_Pending_RowUpdating" OnRowEditing="gv_Pending_RowEditing"
OnRowCancelingEdit="gv_Pending_RowCancelingEdit" OnRowCommand="gv_Pending_RowCommand"
ClientIDMode="Static" >
<Columns>
<asp:CommandField ShowCancelButton="true" ShowEditButton="true" />
<asp:TemplateField HeaderText="Approval" Visible="true">
<ItemTemplate>
<asp:DropDownList ID="ddl_Pending" runat="server" OnSelectedIndexChanged="ddlPending_SelectedIndexChanged"
Enabled="false" >
<asp:ListItem >Select One</asp:ListItem>
<asp:ListItem >Standard Privilege</asp:ListItem>
<asp:ListItem >Admin Privilege</asp:ListItem>
<asp:ListItem >Deny Request</asp:ListItem>
<asp:ListItem >Remove Account</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Field 1" DataField="Field 1 data" ReadOnly="true" />
<asp:BoundField HeaderText="Field 2" DataField="Field 2 data" ReadOnly="true" />
</Columns>
</asp:GridView>
答案 0 :(得分:0)
对于可能追随我的其他人来说,这是一个加载顺序问题。
特别是,我在page_load上回调了网格视图加载事件。这会重置DDL,并自然地消除了在行更新事件期间所做的选择。通过从page_load中删除网格视图加载事件调用,在行更新事件期间进行的DDL选择将按预期保持不变。