页面代码:
<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. HDU 5811 Colosseo

    首先判断一下两个集合是否能够拓扑排序,顺便记录下每个节点的拓扑序. 然后看T2中每个点在T1中能够放在哪一个位置,记录下这个位置Pi. 然后T2中(按拓扑序排好),计算Pi的一个非严格递增的LIS.L ...

  2. WIN7 64位 IE10打开WEB管理提示证书不安全

    用IE10只要在CMD里运行 certutil -setreg chain\minRSAPubKeyBitLength 512 就好了

  3. 一个机器学习博客 ,包括 Standford公开课machine learning

    http://blog.csdn.net/abcjennifer/article/category/1173803/4 http://blog.csdn.net/abcjennifer/article ...

  4. SSH-KeyGen 的用法

    假设 A 为客户机器,B为目标机: 要达到的目的:A机器ssh登录B机器无需输入密码:加密方式选 rsa|dsa均可以,默认dsa 做法:1.登录A机器 2.ssh-keygen -t [rsa|ds ...

  5. poj_2778_DNA Sequence(AC自动机+矩阵)

    题目链接:poj_2778_DNA Sequence 题意: 有m个模式串,然后给你一个长度n,问你n长度的DNA序列有多少种不包含这m个模式串 题解: 这题显然要用AC自动机,将模式串的AC自动机建 ...

  6. hdu_2110_Crisis of HDU(母函数)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2110 题意:给你N个价值和数目,求方案数,很裸的母函数. #include<cstdio> ...

  7. MySQL 的实时性能监控利器【转】

    操作系统及MySQL数据库的实时性能状态数据尤为重要,特别是在有性能抖动的时候,这些实时的性能数据可以快速帮助你定位系统或MySQL数据库的性能瓶颈,就像你在Linux系统上使用「top,sar,io ...

  8. Ansible9:条件语句【转】

    在有的时候play的结果依赖于变量.fact或者是前一个任务的执行结果,从而需要使用到条件语句. 一.when    有的时候在特定的主机需要跳过特定的步骤,例如在安装包的时候,需要指定主机的操作系统 ...

  9. 判断数字 字母 isDigit(), isalpha()

    判断是否是数字 isdigit isNumber      二者区别http://www.cnblogs.com/xiashengwang/p/3219925.html     需要包含头文件  #i ...

  10. git clone分支

    有时git clone下来会出现很多branch,更麻烦的是如果主分支没代码那你就只能看到.git目录了.如下面的这个: $ git clonegit://gitorious.org/android- ...