GridView 中绑定DropDownList ,下拉框默认选中Label的值
2024-08-24 00:58:30
在GridView中,我们 有时候要绑定值。
前台绑定的代码可以这样
<asp:TemplateField HeaderText="当前状态" ItemStyle-HorizontalAlign="Center">
<EditItemTemplate>
<asp:DropDownList ID="dStatus" DataSource='<%#BindStatus()%>' DataTextField="Name" DataValueField="ID" runat="server">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lStatus" runat="server" Text='<%#Bind("Status") %>'></asp:Label>
</ItemTemplate> <ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
为了在后台选择编辑的时候,DropDownList默认选中的值为 <asp:Label ID="lStatus" runat="server" Text='<%#Bind("Status") %>'></asp:Label>的值
在后台代码中,点击编辑实践中添加以下代码:
protected void gvProject_RowEditing(object sender, GridViewEditEventArgs e)
{
Label lstus = (Label)gvProject.Rows[e.NewEditIndex].FindControl("lStatus");
gvProject.EditIndex = e.NewEditIndex;
Bind();
DropDownList ddList=(DropDownList)gvProject.Rows[e.NewEditIndex].FindControl("dStatus");
ddList.SelectedItem.Text = lstus.Text;
}
最新文章
- 我的MYSQL学习心得(八) 插入 更新 删除
- vector迭代器用法
- [Hadoop大数据]——Hive连接JOIN用例详解
- JAVA如何调用C/C++方法
- 新建一个Activity通过按钮打开它,再通过按钮关闭它
- <;经验杂谈>;C#中一种最简单、最基本的反射(Reflection):通过反射获取方法函数
- 编程基础——C/C++,Java,ObjC讨论回调模式
- Apache2.4.x与Apache2.2.x的一些区别
- 《Effective Objective-C 2.0》 读后总结
- “此主机支持 Intel VT-x,但 Intel VT-x 处于禁用状态”的问题的解决
- DataTables ajax + bootstrap 分页/搜索/排序/常见问题
- Conjugate
- .NET英文技术文章导读(2017-02-09)
- [Css] css3的flex布局
- 2 Class类
- JavaScript之DOM对象的获取
- PyCharm中快速给选中的代码加上{}、<;>;、()、[]
- vue 中的slot属性(插槽)的使用
- GCC输出带C源代码的汇编文件
- ODAC(V9.5.15) 学习笔记(四)TCustomDADataSet(2)
热门文章
- 点滴记录——Ubuntu 14.04中Chrome浏览器标题栏出现中文乱码
- 【iOS系列】-textView的非常规使用
- GoodUI:页面布局的技巧和设计理念
- VisualSVN Server的配置和使用
- ubuntu下nginx的安裝
- problem in Sourcetree
- AutoIT: WinSetState可以定义窗口大小
- bzoj1878 [SDOI2009]HH的项链——树状数组
- EF 6.0 The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. c#中的时间
- 简单粗暴解决google被和谐导致google fonts无法加载的问题