zoukankan      html  css  js  c++  java
  • 在ListView中使用DropDownList绑定数据……好麻烦

    在Aspx页中的代码:

    <EditItemTemplate>
        
    <asp:DropDownList ID="DropDownList1" runat="server">
            
    <asp:ListItem Value=""></asp:ListItem>
            
    <asp:ListItem Value=""></asp:ListItem>
        
    </asp:DropDownList>
    </EditItemTemplate>

     添加事件:ItemUpdating和ItemCreated事件

     protected void ListView1_ItemUpdating(object sender, ListViewUpdateEventArgs e)
            {
                
    //在更新之前绑定DropDownList
                DropDownList ddGender = (DropDownList)ListView1.Items[e.ItemIndex].FindControl("DropDownList1");
                e.NewValues[
    "Gender"= ddGender.SelectedValue;
            }
    protected void ListView1_ItemCreated(object sender, ListViewItemEventArgs e)
            {
                
    if (e.Item.ItemType == ListViewItemType.DataItem)
                {
                    DropDownList ddlGender 
    = (DropDownList)e.Item.FindControl("DropDownList1");
                    
    if (ddlGender != null)
                    {
                        ListViewDataItem lvDataItem 
    = (ListViewDataItem)e.Item;
                        DataRowView rowView 
    = (DataRowView)lvDataItem.DataItem;
                        
    if (rowView != null)
                        {
                            var userRow 
    = (DataSetUsers.UsersRow)rowView.Row;
                            ddlGender.SelectedValue 
    = userRow.Gender;
                        }
                    }
                }
            }
     protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
            {
                
    if (e.Item.ItemType == ListViewItemType.DataItem)
                {
                    DropDownList ddlLinkType 
    = (DropDownList)e.Item.FindControl("DropDownList1");
                    ListViewDataItem lvDataItem 
    = (ListViewDataItem)e.Item;
                    DataRowView rowView 
    = (DataRowView)lvDataItem.DataItem;
                    
    if (ddlLinkType != null && rowView != null)
                    {
                        var linksRow 
    = (DAL.DataSetLinks.T_LinksRow)rowView.Row;
                        ddlLinkType.SelectedValue 
    = linksRow.LinkType;
                    }
                }
            }

            
    protected void ListView1_ItemInserting(object sender, ListViewInsertEventArgs e)
            {
                DropDownList ddlLinkType 
    = (DropDownList)e.Item.FindControl("DropDownList1");
                e.Values[
    "LinkType"= ddlLinkType.SelectedValue;
            }

            
    protected void ListView1_ItemUpdating(object sender, ListViewUpdateEventArgs e)
            {
                DropDownList ddlLinkType 
    = (DropDownList)ListView1.Items[e.ItemIndex].FindControl("DropDownList1");
                e.NewValues[
    "LinkType"= ddlLinkType.SelectedValue;
            }
        }
  • 相关阅读:
    [转]P2P原理和常见实现方法
    google naming
    【转】CvArr、Mat、CvMat、IplImage、BYTE转换(总结而来)
    Ubuntu 下 JDK7.0和eclipse安装
    BSP模型简单介绍
    2012最受企业欢迎的开发技能Top10 转
    Social Network Analysis
    python操作mysql
    ASP、ASP.NET、JSP、PHP等网页服务器语言的比较
    mysql 正则表达式 regexp
  • 原文地址:https://www.cnblogs.com/zhuiyi/p/2042784.html
Copyright © 2011-2022 走看看