页面代码:
<asp:GridView ID="GridView1" runat="server" 
           AutoGenerateColumns="False" Width="650px" Font-Size="12px" ForeColor ="#43860c" 
           DataKeyNames="user_id" onrowcancelingedit="GridView1_RowCancelingEdit" 
           onrowdeleting="GridView1_RowDeleting" onrowediting="GridView1_RowEditing" 
           onrowupdating="GridView1_RowUpdating" ondatabound="GridView1_DataBound" 
           AllowPaging="True" onrowdatabound="GridView1_RowDataBound" 
          >
           <Columns>
               <asp:BoundField DataField="user_id" HeaderText="编号"ReadOnly="True" />
               <asp:BoundField DataField="user_name" HeaderText="姓名"/>
               <asp:BoundField DataField="contact" HeaderText="联系电话"/>
               <asp:BoundField DataField="company_name" HeaderText="公司名称"/>
               <asp:BoundField DataField="address" HeaderText="地址"/>
               <asp:BoundField DataField="custom_demand" HeaderText="客户需求"/>
               <asp:BoundField DataField="date" HeaderText="日期"ReadOnly="True" />
                <asp:TemplateField HeaderText="状态">
                                <ItemTemplate>
                                    <asp:Label ID="Label1" runat="server" Text='<%#showUserName(Eval("status"))%>'></asp:Label> 
                                </ItemTemplate>
                                <EditItemTemplate > 
                                    <asp:Label ID="Label2" runat="server" Text='<%#showUserName(Eval("status"))%>' Visible ="false"></asp:Label>                   
                                 <asp:DropDownList ID="DropDownList1" runat="server" Font-Size="12px" ForeColor="#43860c">                                   
                                  
                                             <asp:ListItem Value="0" Text ="有意向"></asp:ListItem>
                                             <asp:ListItem Value="1" Text ="已签约"></asp:ListItem>
                                             <asp:ListItem Value="2" Text ="已关闭"></asp:ListItem>
                                   </asp:DropDownList></EditItemTemplate>
                            </asp:TemplateField>
               <asp:BoundField DataField="remark" HeaderText="备注"/>
               <asp:CommandField ShowEditButton="True" />
               <asp:CommandField ShowDeleteButton="True" DeleteText="删除"/>
           </Columns>
                  <PagerTemplate>
        <br />
         <asp:Label ID="lblPage" runat="server" Text='<%# "第" + (((GridView)Container.NamingContainer).PageIndex + 1) + "页/共" + (((GridView)Container.NamingContainer).PageCount) + "页" %> '></asp:Label>
         <asp:LinkButton ID="lbnFirst" runat="Server" Text="首页" ForeColor="#43860c" Font-Size="12px"
                    Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>' 
                    CommandName="Page" CommandArgument="First" Font-Underline="False" ></asp:LinkButton>
       &nbsp <asp:LinkButton ID="lbnPrev" runat="server" Text="上一页"ForeColor="#43860c" Font-Size="12px"
                    Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>' 
                    CommandName="Page" CommandArgument="Prev" Font-Underline="False" ></asp:LinkButton>
        &nbsp <asp:LinkButton ID="lbnNext" runat="Server" Text="下一页"ForeColor="#43860c" Font-Size="12px"
                    Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>' 
                    CommandName="Page" CommandArgument="Next" Font-Underline="False" ></asp:LinkButton>
        &nbsp <asp:LinkButton ID="lbnLast" runat="Server" Text="尾页"ForeColor="#43860c" Font-Size="12px" 
                    Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>' 
                    CommandName="Page" CommandArgument="Last" Font-Underline="False" ></asp:LinkButton>
                     &nbsp;&nbsp; 到第<asp:TextBox runat="server" ID="inPageNum" Height="19px" Width="74px"></asp:TextBox>页 
         <asp:Button ID="Button1" CommandName="go" runat="server" Text="go" Width="50px" />
         <br />
     </PagerTemplate> 
                
           </asp:GridView>
 
C#代码
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (((DropDownList)e.Row.FindControl("DropDownList1")) != null)//判断有没有DropDownList
        {
            DropDownList ddl = (DropDownList)e.Row.FindControl("DropDownList1");
                  string lbl = ((Label)e.Row.FindControl("Label2")).Text;//获Label2的值
            ddl.Items.FindByText(lbl).Selected = true;//设置ddl的默认值
 
        }
    }

在Gridview编辑时添加DropDownList控件并设置默认值的更多相关文章

  1. 关于EasyUI DataGrid行编辑时嵌入时间控件

    本人做一个名为“安徽中控”项目时,为快速开发基础数据增删改模块,遂采用EasyUIDatagrid将所有增删改查的操作都集中于表格中,并且所有增删改查操作都集中于泛型对象,从而不必为每个表写具体的增删 ...

  2. Winform中使用DevExpress时给控件添加子控件的方法

    场景 在WInform中使用DevExpress时经常使用PanelControl控件用来进行布局设计,因此需要在代码中生成控件并添加子控件. 实现 一种是设置要添加的自控件的Parent属性为容器控 ...

  3. C# 给Word文档添加内容控件

    C# 给Word文档添加内容控件 在MS Word中,我们可以通过内容控件来向word文档中插入预先定义好的模块,指定模块的内容格式(如图片.日期.列表或格式化的文本等),从而创建一个结构化的word ...

  4. 在FooterTemplate内显示DropDownList控件

    如果想在Gridview控件FooterTemplate内显示DropDownList控件供用户添加数据时所应用.有两种方法可以实现,一种是在GridView控件的OnRowDataBound事件中写 ...

  5. WPF下可编辑Header的Tab控件实现

    介绍 有这样一个需求,当用户双击Tab控件Header区域时, 希望可以直接编辑.对于WPF控件,提供一个ControlTemplate在加上一些Trigger就可以实现.效果如下: 代码 首先,我们 ...

  6. DropDownList控件

    1.DropDownList控件 <asp:DropDownList runat="server" ID="DropDownList1" AutoPost ...

  7. DropDownList 控件不能触发SelectedIndexChanged 事件

    相信DropDownList 控件不能触发SelectedIndexChanged 事件已经不是什么新鲜事情了,原因也无外乎以下几种: 1.DropDownList 控件的属性 AutoPostBac ...

  8. 三级联动---DropDownList控件

    AutoPostBack属性:意思是自动回传,也就是说此控件值更改后是否和服务器进行交互比如Dropdownlist控件,若设置为True,则你更换下拉列表值时会刷新页面(如果是网页的话),设置为fl ...

  9. TWaver初学实战——如何在TWaver属性表中添加日历控件?

    在日期输入框中添加日历控件,是一种非常流行和实用的做法.临渊羡鱼不如退而写代码,今天就看看在TWaver中是如何实现的.   资源准备   TWaver的在线使用文档中,就有TWaver Proper ...

随机推荐

  1. 在OSchina上看到的清理到缓存的方法

    /* * *文 件 名: DataCleanManager.java * 描 述: 主要功能有清除内/外缓存,清除数据库,清除sharedPreference,清除files和清除自定义目录 */ i ...

  2. form异步无刷新提交,提交后可以显示弹出框,否则弹出框会被刷新不见,使用 preventDefault

    出错点:确认按钮上.加onclick事件.每次点击都会追加给form追加on监听方法.累加on方法,重复提交 suppress_exception:true 阻止异常 (百度推送 jdk) 向下按 p ...

  3. Centos下 Nginx安装与配置

    网上找了好多资料.都很难找全,这里以这个目录为主,进行备注. Nginx是一款轻量级的网页服务器.反向代理服务器.相较于Apache.lighttpd具有占有内存少,稳定性高等优势.它最常的用途是提供 ...

  4. 20150627分享iOS开发笔记

    util是工具的意思:Ad Hoc是特别的,临时的意思;validate是验证的意思: 打包 苹果的键盘真好使 6和6 plus真机测试报错:No architectures to compile f ...

  5. Qt 5简介

    Qt 5简介 Qt 5概要介绍 在Qt 5这个版本中,Qt Quick成为了Qt的核心.但是Qt 5也继续提供了本地C++强大的功能来完成更好的用户体验,也提供了对OpenGL/OpenGL ES图形 ...

  6. mysql grant授权

    MySQL 赋予用户权限命令的简单格式可概括为: grant 权限 on 数据库对象 to 用户 一.grant 普通数据用户,查询.插入.更新.删除 数据库中所有表数据的权利. grant sele ...

  7. get 和 post请求的区别

    (1)GET请求用于获取信息,从Client的角度看,不会改变资源状态,并且多次对同一URL的多个请求应该返回相同的结果.        GET请求的参数会显示在URL中,即放置在HTTP协议头中(所 ...

  8. 贪心<haonan>

    题意: 有一列数,每次在相邻的两个书里面选择一个大数留下,同时ans+大数.问题是,求ans的最小值. 题解: 如果a[i]>a[i-1],那么ans+=a[i]; 如果a[i]>=a[i ...

  9. php 版本比较

    判断当前运行的 PHP 版本是否高于或等于你提供的版本号. function is_php($version) { static $_is_php; $version = (string) $vers ...

  10. iOS8中的动态文本

    原文链接 : Swift Programming 101: Mastering Dynamic Type in iOS 8 原文作者 : Kevin McNeish Apple声称鼓励第三方App能够 ...