页面代码:
<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 5765 Bonds

    比赛时候想了好久,不会.看了官方题解才会...... Bond是极小割边集合,去掉一个Bond之后,只会将原图分成两个连通块. 假设某些点构成的集合为 s(点集中的点进行状压后得到的一个十进制数),那 ...

  2. 《Windows驱动开发技术详解》之读写操作

    缓冲区方式读写操作 设置缓冲区读写方式:

  3. (转载)解析ISO8583报文实例

    本篇文章参考了中国银联POS终端规范,所以如有不明白的可以去我的资源里面下载. 现在我们有ISO8583报文如下(十六进制表示法): 60 00 03 00 00(前五个字节为TPDU) 60 31 ...

  4. EntityFramwork所有 SSDL 项目都必须以同一提供程序为目标。ProviderManifestToken“2008”不同于以前遇到的“2005”

    再用spring+mvc+EF搭建框架时,出现这个问题,网上没有找到类似的问题,删除实体重建后莫名其妙的好了,2008指的是连得数据库实例是2008版本的,2005指的是2005版本,出现问题的原因是 ...

  5. ado vb6

    http://www.cnblogs.com/ywb-lv/articles/2343444.html http://stackoverflow.com/questions/3334102/use-t ...

  6. github  安装配置以及使用遇到的一些问题

    Git是一个分布式的版本控制系统,最初由Linus Torvalds编写,用作Linux内核代码的管理.在推出后,Git在其它项目中也取得了很大成功,尤其是在Ruby社区中.目前,包括Rubinius ...

  7. 【中国剩余定理】 poj 1006

    生理周期  简单模拟 对于超出23 * 28 * 33(21252)时进行求余运算即可. #include<stdio.h> int main() { //freopen("in ...

  8. navicat连接oracle时发现 ORA-12737 set CHS16GBK

    oracle安装目录下找到目录:\product\11.2.0\dbhome_1\BIN, 将箭头标注的三个文件(截图中为navicat中的目录,已经测试成功,亲们可以参考)从目录中拷贝纸navica ...

  9. opencv基础知识------IplImage, CvMat, Mat 的关系和相互转换

    Mat,cvMat和IplImage这三种类型都可以代表和显示图像,但是,Mat类型侧重于计算,数学性较高,openCV对Mat类型的计算也进行了优化.而CvMat和IplImage类型更侧重于“图像 ...

  10. 动态链接库dll,导入库lib,静态链接库lib

    目前以lib后缀的库有两种,一种为静态链接库(Static Libary,以下简称“静态库”),另一种为动态连接库(DLL,以下简称“动态库”)的导入库(Import Libary,以下简称“导入库” ...