在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;
}
												

最新文章

  1. 我的MYSQL学习心得(八) 插入 更新 删除
  2. vector迭代器用法
  3. [Hadoop大数据]——Hive连接JOIN用例详解
  4. JAVA如何调用C/C++方法
  5. 新建一个Activity通过按钮打开它,再通过按钮关闭它
  6. &lt;经验杂谈&gt;C#中一种最简单、最基本的反射(Reflection):通过反射获取方法函数
  7. 编程基础——C/C++,Java,ObjC讨论回调模式
  8. Apache2.4.x与Apache2.2.x的一些区别
  9. 《Effective Objective-C 2.0》 读后总结
  10. “此主机支持 Intel VT-x,但 Intel VT-x 处于禁用状态”的问题的解决
  11. DataTables ajax + bootstrap 分页/搜索/排序/常见问题
  12. Conjugate
  13. .NET英文技术文章导读(2017-02-09)
  14. [Css] css3的flex布局
  15. 2 Class类
  16. JavaScript之DOM对象的获取
  17. PyCharm中快速给选中的代码加上{}、&lt;&gt;、()、[]
  18. vue 中的slot属性(插槽)的使用
  19. GCC输出带C源代码的汇编文件
  20. ODAC(V9.5.15) 学习笔记(四)TCustomDADataSet(2)

热门文章

  1. 点滴记录——Ubuntu 14.04中Chrome浏览器标题栏出现中文乱码
  2. 【iOS系列】-textView的非常规使用
  3. GoodUI:页面布局的技巧和设计理念
  4. VisualSVN Server的配置和使用
  5. ubuntu下nginx的安裝
  6. problem in Sourcetree
  7. AutoIT: WinSetState可以定义窗口大小
  8. bzoj1878 [SDOI2009]HH的项链——树状数组
  9. EF 6.0 The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. c#中的时间
  10. 简单粗暴解决google被和谐导致google fonts无法加载的问题