• datagrid加下拉列表dropdownlist


     datagrid中代码:

    <asp:datagrid id="dgList" runat="server" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center"
                                    HorizontalAlign="Center" PageSize="5" AutoGenerateColumns="False" GridLines="Horizontal" CellPadding="1" BackColor="White"
                                    BorderWidth="1px" BorderStyle="None" BorderColor="#E7E7FF" Width=100%  OnItemDataBound="DataGrid1_ItemDataBound">
                                    <FooterStyle ForeColor="#4A3C8C" BackColor="#B5C7DE"></FooterStyle>
                                    <SelectedItemStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#738A9C"></SelectedItemStyle>
                                    <AlternatingItemStyle BackColor="#F7F7F7"></AlternatingItemStyle>
                                    <ItemStyle HorizontalAlign="Center" ForeColor="#4A3C8C" BackColor="#E7E7FF"></ItemStyle>
                                    <HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="#F7F7F7" BackColor="#4A3C8C"></HeaderStyle>
                                    <Columns>
         <asp:templatecolumn HeaderText="状态">
            <itemtemplate>
                <asp:dropdownlist  id="ItemDropDown" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDown_SelectedIndexChanged"/>
            </itemtemplate>
        </asp:TemplateColumn>
        <asp:TemplateColumn>
            <ItemTemplate>
                <asp:Button id="SaveButton" Visible="false" runat="server"  CommandName="save" Text="保存"></asp:Button>
            </ItemTemplate>
        </asp:templatecolumn>
        <PagerStyle ForeColor="#4A3C8C" BackColor="#E7E7FF" Mode="NumericPages"></PagerStyle>
    </asp:datagrid>
    private void InitializeComponent()
            {
                this.dgList.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgList_ItemCommand);
            }
    
      protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
            {
                if (e.Item.ItemType == ListItemType.AlternatingItem ||
                   e.Item.ItemType == ListItemType.Item)
                {
                    string[] options = { "", "已通知", "变更邮箱中", "联系不上", "商户要注销" };
    
                    DropDownList list = (DropDownList)e.Item.FindControl("ItemDropDown");
                    list.DataSource = options;
                    list.DataBind();
    
                    TableCell cell = list.Parent as TableCell;
                    DataGridItem item = cell.Parent as DataGridItem;
    
                    int index = item.ItemIndex;
                    list.SelectedValue = item.Cells[1].Text;
                }
            }
            
     protected void DropDown_SelectedIndexChanged(object sender, EventArgs e)
            {
                DropDownList list = (DropDownList)sender;
    
                TableCell cell = list.Parent as TableCell;
                DataGridItem item = cell.Parent as DataGridItem;
    
                int index = item.ItemIndex;
                string content = item.Cells[12].Text;
               // DropDownList down = (DropDownList)item.FindControl("ItemDropDown");
                string checkState = list.SelectedValue.Trim();
    
                object obj = item.Cells[13].FindControl("queryButton");
                if (obj != null)
                {
                    Button lb = (Button)obj;
                    lb.Visible = true;//动下拉列表就显示保存按钮
                }
            }
            
     private void dgList_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
            {
                string spid = e.Item.Cells[2].Text.Trim();
                string crt_etime = e.Item.Cells[8].Text.Trim();
                string state = e.Item.Cells[12].Text.Trim();
              
                try
                {
                    if (e.CommandName == "save") ;
                    …………………………//保存
                }
                catch (Exception eSys)
                {
                    WebUtils.ShowMessage(this.Page, "保存数据失败!" + eSys.Message);
                }
            }
  • 相关阅读:
    (视频) 《快速创建网站》 2.2 负载均衡简介和域名绑定操作
    (视频) 《快速创建网站》2.1 在Azure上创建网站及网站运行机制
    (视频) 《快速创建网站》1. 网站管理平台WordPress & 微软Azure 云计算简介
    (视频) 开源,免费和跨平台 - MVP ComCamp 2015 KEYNOTE
    【Flask教程01】helloworld程序
    如何在虚拟环境中安装工具包?
    如何使用虚拟环境?
    CentOS 使用ifconfig没有显示ip
    Python Web框架要点
    Python3.7&Django1.11.15 兼容性问题
  • 原文地址:https://www.cnblogs.com/echolxl/p/3834089.html
Copyright © 2020-2023  润新知