您的位置:首页 > 运维架构

GridView中编辑状态下实现DropDownList默认值(原创)

2009-12-14 09:31 435 查看
之前看到很多网友包括孟子e章兄的默认值方法,觉得比较麻烦,自己写了个简单方法,欢迎大家指证!

前台:

<asp:TemplateField HeaderText="资质">
<ItemTemplate>
<asp:Label ID="lblAptitude" runat="server" Text='<%#Eval("Aptitude") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lbl2" runat="server" Text='<%#Eval("Aptitude") %>' style="display:none;"></asp:Label>
<asp:DropDownList ID="ddlAptitude" runat="server">
<asp:ListItem Value="合格" Text="合格"></asp:ListItem>
<asp:ListItem Value="储备" Text="储备"></asp:ListItem>
<asp:ListItem Value="潜在" Text="潜在"></asp:ListItem>
<asp:ListItem Value="不合格" Text="不合格"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>

后台:

protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex == gvList.EditIndex)
{
//编辑时下拉菜单默认值
ddlAptitude.Text = ((Label)e.Row.FindControl("lbl2")).Text;
}

}

欢迎大家发表意见,xiexie
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: