zoukankan      html  css  js  c++  java
  • [原创]Datagrid中绑定DropDownList的例子

    Html代码

    <form id="Form1" method="post" runat="server">
                     
    <asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 224px; POSITION: absolute; TOP: 184px"
                           runat
    ="server" AutoGenerateColumns="False" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px"
                           BackColor
    ="White" CellPadding="3" GridLines="Horizontal">                        <SelectedItemStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#738A9C"></SelectedItemStyle>                        <AlternatingItemStyle BackColor="#F7F7F7"></AlternatingItemStyle>                        <ItemStyle ForeColor="#4A3C8C" BackColor="#E7E7FF"></ItemStyle>                        <HeaderStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#4A3C8C"></HeaderStyle>                        <FooterStyle ForeColor="#4A3C8C" BackColor="#B5C7DE"></FooterStyle>                        <Columns>
                                 
    <asp:TemplateColumn HeaderText="111">
                                       
    <EditItemTemplate>
                                             
    <asp:DropDownList ID="d" Runat="server"></asp:DropDownList>                                    </EditItemTemplate>
                                 
    </asp:TemplateColumn>
                                 
    <asp:BoundColumn DataField="Stringvalue" HeaderText="Stringvalue"></asp:BoundColumn>                              <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" HeaderText="Edit" CancelText="Cancel"
                                       EditText
    ="Edit"></asp:EditCommandColumn>
                           
    </Columns>
                           
    <PagerStyle HorizontalAlign="Right" ForeColor="#4A3C8C" BackColor="#E7E7FF" Mode="NumericPages"></PagerStyle>                  </asp:DataGrid>
               
    </form>

    后台代码 .VB 

     
    Private Sub Page_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load
            
    If Not IsPostBack Then
                bind()
            
    End If
        
    End Sub

        

            
    Dim d As New Data
            DataGrid1.DataSource 
    = d.CreateDataSource()
            DataGrid1.DataBind()
        
    End Sub

        
    Private Sub DataGrid1_EditCommand(ByVal source As ObjectByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand
            DataGrid1.EditItemIndex 
    = e.Item.ItemIndex
            bind()
            

        
    End Sub


        
    Private Sub DataGrid1_ItemDataBound(ByVal sender As ObjectByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
            
    If e.Item.ItemType = ListItemType.EditItem Then
                
    Dim d1 As New DropDownList
                
    Dim d As New Data
                d1 
    = CType(e.Item.FindControl("d"), DropDownList)
                d1.DataSource 
    = d.CreateDataSource()
                d1.DataTextField 
    = "Stringvalue"
                d1.DatavalueField = "Integervalue"
                d1.DataBind()
            
    End If
        
    End Sub




    C#代码

    private void Page_Load(object sender, System.EventArgs e) 

     
    if (!(IsPostBack)) 
       bind(); 
     }
     
    }
     

    void bind() 

     Data d 
    = new Data(); 
     DataGrid1.DataSource 
    = d.CreateDataSource(); 
     DataGrid1.DataBind(); 
    }
     

    private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) 

     DataGrid1.EditItemIndex 
    = e.Item.ItemIndex; 
     bind(); 
    }
     

    private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) 

     
    if (e.Item.ItemType == ListItemType.EditItem) 
       DropDownList d1 
    = new DropDownList(); 
       Data d 
    = new Data(); 
       d1 
    = ((DropDownList)(e.Item.FindControl("d"))); 
       d1.DataSource 
    = d.CreateDataSource(); 
       d1.DataTextField 
    = "Stringvalue"
       d1.DatavalueField 
    = "Integervalue"
       d1.DataBind(); 
     }
     
    }

  • 相关阅读:
    [zjoi]青蛙的约会_扩展欧几里德
    [coci2012]覆盖字符串 AC自动机
    出题日志
    [zjoi2003]密码机
    矩阵乘法
    洛谷 P1064 金明的预算方案
    洛谷 P1656 炸铁路
    洛谷 P1049 装箱问题
    最长上升子序列(LIS)与最长公共子序列(LCS)
    求最大公约数与最小公倍数
  • 原文地址:https://www.cnblogs.com/goody9807/p/182560.html
Copyright © 2011-2022 走看看