Datagrid Bind DropDownlist.....

 
DataGrid 中绑定Dropdownlist
 
Menu_Init.ascx.vb 前台页面
<% @ Control Language="VB" AutoEventWireup="false" CodeFile="Menu_Init.ascx.vb" Inherits="LiveWork.Menu_Init" %>
< table border="0" cellpadding="0" cellspacing="0" style="width: 100%; height: 37%">
    <tr>
        <td style="width: 100%; height: 230px">
            <table border="0" bordercolor="#888888" bordercolordark="#ffffff" cellpadding="0"
                cellspacing="0" width="90%">
                <tr>
                    <td align="left" style="width: 100%; height: 14px" valign="top">
                    </td>
                </tr>
            </table>
            <table border="1" bordercolor="#888888" bordercolordark="#ffffff" cellpadding="0"
                cellspacing="0" width="100%">
                <tr>
                    <td align="left" style="width: 679px; height: 14px" valign="top">
                        Add New Rold</td>
                </tr>
            </table>
            <table border="1" bordercolor="#888888" bordercolordark="#ffffff" cellpadding="0"
                cellspacing="0" width="100%">
                <tr>
                    <td align="left" style="width: 111px; height: 23px" valign="top">
                        Menu ID</td>
                    <td align="left" style="width: 679px; height: 23px" valign="top">
                        <asp:TextBox ID="Tbx_Menu_ID" runat="server" BackColor="Silver" ForeColor="Blue"
                            ReadOnly="True" Width="78px"></asp:TextBox></td>
                </tr>
                <tr>
                    <td align="left" style="width: 111px; height: 23px" valign="top">
                        Level Code</td>
                    <td align="left" style="width: 679px; height: 23px" valign="top">
                        <asp:DropDownList ID="DropDownList_Level_Code" runat="server" Width="154px">
                        </asp:DropDownList></td>
                </tr>
                <tr>
                    <td align="left" style="width: 111px; height: 21px" valign="top">
                        Menu Name</td>
                    <td align="left" style="width: 679px; height: 21px" valign="top">
                        <asp:TextBox ID="Tbx_Menu_Name" runat="server" Width="263px"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="Tbx_Menu_Name"
                            ErrorMessage="Menu Name Must Fill!">*</asp:RequiredFieldValidator></td>
                </tr>
                <tr>
                    <td align="left" style="width: 111px; height: 22px">
                        Url</td>
                    <td align="left" style="width: 679px; height: 22px">
                        <asp:TextBox ID="TextBox_Url" runat="server" Width="476px"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox_Url"
                            ErrorMessage="Url Must Fill!">*</asp:RequiredFieldValidator></td>
                </tr>
                <tr>
                    <td align="left" style="width: 111px; height: 22px">
                        Status</td>
                    <td align="left" style="width: 679px; height: 22px">
                        <asp:DropDownList ID="DropDownList_Status" runat="server" Width="154px">
                        </asp:DropDownList></td>
                </tr>
            </table>
            <table border="1" bordercolor="#888888" bordercolordark="#ffffff" cellpadding="0"
                cellspacing="0" width="100%">
                <tr>
                    <td align="left" style="width: 679px; height: 14px" valign="top">
                        <asp:Button ID="Button_Add" runat="server" Text="Add" Width="61px" /></td>
                </tr>
            </table>
            <table border="0" bordercolor="#888888" bordercolordark="#ffffff" cellpadding="0"
                cellspacing="0" width="100%">
                <tr>
                    <td style="width: 679px; height: 14px" valign="top">
                    </td>
                </tr>
            </table>
            <table border="1" bordercolor="#888888" bordercolordark="#ffffff" cellpadding="0"
                cellspacing="0" width="100%">
                <tr>
                    <td style="width: 100%; height: 14px" valign="top">
                        <asp:DataGrid ID="DataGrid_MenuList" runat="server" AutoGenerateColumns="False" BackColor="#F7F7F7"
                            BorderColor="#F7F7F7" BorderStyle="Solid" BorderWidth="1px" CssClass="table"
                            DataKeyField="ID" Font-Size="X-Small" Width="100%">
                            <FooterStyle CssClass="headcenter" />
                            <EditItemStyle BackColor=LightGrey ForeColor="Black" Width="100%" />
                            <SelectedItemStyle BackColor="Transparent" />
                            <AlternatingItemStyle BackColor="White" BorderColor="White" />
                            <ItemStyle BackColor="#DEDFDE" CssClass="textcenter" />
                            <HeaderStyle CssClass="headcenter" />
                            <Columns>
                           <asp:TemplateColumn HeaderText="Level ID">
                            <EditItemTemplate>
                                     <asp:DropDownList id=DropDownList_Level_D runat="server" Width="112px">
                                     </asp:DropDownList>
                                     <asp:Label runat="server" id="Level_Code_L" Visible="False" Text='<%# DataBinder.Eval(Container, "DataItem.Level_Name") %>' />
                                 </EditItemTemplate>
                               </asp:TemplateColumn>                         
                                <asp:BoundColumn DataField="Menu_ID" HeaderText="Menu ID"></asp:BoundColumn>
                                <asp:BoundColumn DataField="Menu_Name" HeaderText="Menu Name"></asp:BoundColumn>
                                <asp:BoundColumn DataField="Url" HeaderText="Url"></asp:BoundColumn>      
                                 <asp:TemplateColumn HeaderText="Status">
                            <EditItemTemplate>
                                     <asp:DropDownList id=DropDownList_Status_D runat="server" Width="112px">
                                     </asp:DropDownList>
                                     <asp:Label runat="server" id="Level_Status_L" Visible="False" Text='<%# DataBinder.Eval(Container, "DataItem.Status") %>' />
                                 </EditItemTemplate>
                               </asp:TemplateColumn>                                
                             
                                <asp:TemplateColumn HeaderText="Update Menu">
                                    <ItemStyle Width="20%" />
                                    <ItemTemplate>
                                        <asp:LinkButton ID="Linkbutton1" runat="server" CausesValidation="false" CommandName="Edit"
                                            NAME="Linkbutton1" Text="Edit"></asp:LinkButton>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <asp:LinkButton ID="Linkbutton2" runat="server" CausesValidation="false" CommandName="Update"
                                            NAME="Linkbutton2" Text="Update"></asp:LinkButton>&nbsp;
                                        <asp:LinkButton ID="Linkbutton3" runat="server" CausesValidation="false" CommandName="Cancel"
                                            NAME="Linkbutton3" Text="Cancel"></asp:LinkButton>
                                    </EditItemTemplate>
                                </asp:TemplateColumn>
                                <asp:TemplateColumn HeaderText="Delete">
                                    <ItemStyle Width="10%" />
                                    <ItemTemplate>
                                        <asp:ImageButton ID="Imagebutton2" runat="server" AlternateText="Delete this item"
                                            CommandName="Delete" ImageUrl="~/img/delete.gif" />
                                    </ItemTemplate>
                                </asp:TemplateColumn>
                            </Columns>
                        </asp:DataGrid></td>
                </tr>
            </table>
        </td>
    </tr>
</ table >
 
 
Menu_Init.vb 前台页面
Namespace LiveWork
    Partial Class Menu_Init
        Inherits System.Web.UI.UserControl
 
        Sub InitializeComponent()
            AddHandler DataGrid_MenuList.EditCommand, AddressOf DataGrid_MenuList_EditCommand
        End Sub
 
        Private s1 As String
 
 
        Private Sub BindMenuID()
            Me.Tbx_Menu_ID.Text = Live.ClassSystem.LiveSystem.GetNextID("TB_Menu", "Menu_ID")
        End Sub
 
        Private Sub BindLevelCode()
            Me.DropDownList_Level_Code.DataSource = Live.ClassSystem.LiveSystem.GetLevelCode("TOP")
            Me.DropDownList_Level_Code.DataTextField = "Level_Name"
            Me.DropDownList_Level_Code.DataValueField = "Level_Code"
            Me.DropDownList_Level_Code.DataBind()
            Me.DropDownList_Level_Code.SelectedIndex = 0
 
        End Sub
 
        Private Sub BindStatus()
            Me.DropDownList_Status.DataSource = Live.ClassSystem.LiveSystem.GetStatus
            Me.DropDownList_Status.DataTextField = "Status_Desc_En"
            Me.DropDownList_Status.DataValueField = "Status"
            Me.DropDownList_Status.DataBind()
        End Sub
 
        Private Sub Bind_Load()
            Dim ds As DataSet = Live.ClassSystem.LiveSystem.GetLevelCode("TOP")
            Dim ds1 As DataSet = Live.Ado.ADOProxy.GetAllRows("TB_Status")
            ' If Me.DataGrid_MenuList.EditItemIndex <> -1 Then
            For Each lobj_dgi As DataGridItem In Me.DataGrid_MenuList.Items
                'Dim dl As DropDownList = CType(lobj_dgi.FindControl("DropDownList_Level_D"), DropDownList)
                'dl.DataSource = ds
                'dl.DataTextField = "Level_Name"
                'dl.DataValueField = "Level_Code"
                'dl.DataBind()
                ''dl.SelectedValue = Live.ClassSystem.LiveSystem.GetMenuInfoByMenuID(lobj_dgi.Cells(1).Text).Tables(0).Rows(0).Item("index_id").ToString
                'dl.Enabled = False
                Dim current1 As String
                current1 = "XXXX"
                lobj_dgi.Cells(0).Text = current1
 
                Dim dl1 As DropDownList = CType(lobj_dgi.FindControl("DropDownList_Status_D"), DropDownList)
                dl1.DataSource = ds1
                dl1.DataTextField = "Status_Desc_En"
                dl1.DataValueField = "Status"
                dl1.DataBind()
                'dl1.SelectedValue = Live.ClassSystem.LiveSystem.GetMenuInfoByMenuID(lobj_dgi.Cells(1).Text).Tables(0).Rows(0).Item("status").ToString
                dl1.Enabled = False
            Next
            ' End If
 
        End Sub
 
        Private Sub BindMenu()
            Me.DataGrid_MenuList.DataSource = Live.ClassSystem.LiveSystem.GetUserMenu("TOP")
            Me.DataGrid_MenuList.DataBind()
        End Sub
        Protected Sub Button_Add_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button_Add.Click
 
        End Sub
 
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            BindMenuID()
            BindLevelCode()
            BindStatus()
            BindMenu()
            'Bind_Load()
        End Sub
 
        Protected Sub DataGrid_MenuList_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid_MenuList.EditCommand
 
            DataGrid_MenuList.EditItemIndex = e.Item.ItemIndex
            BindMenu()
 
 
        End Sub
 
        Protected Sub DataGrid_MenuList_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid_MenuList.ItemDataBound
 
            Dim ds1 As DataSet = Live.ClassSystem.LiveSystem.GetLevelCode("TOP")
            Dim ds2 As DataSet = Live.Ado.ADOProxy.GetAllRows("TB_Status")
            ' e.Item.Cells(0).Text = "str"
 
            If e.Item.ItemType = ListItemType.EditItem And e.Item.ItemIndex <> -1 Then
                Dim dl1 As DropDownList = CType(e.Item.FindControl("DropDownList_Level_D"), DropDownList)
                dl1.DataSource = ds1
                dl1.DataTextField = "Level_Name"
                dl1.DataValueField = "Level_Code"
                dl1.DataBind()
                Dim str1 As String = CType(e.Item.FindControl("Level_Code_L"), Label).Text
                dl1.SelectedIndex = dl1.Items.IndexOf(dl1.Items.FindByText(str1))
 
                Dim dl2 As DropDownList = CType(e.Item.FindControl("DropDownList_Status_D"), DropDownList)
                dl2.DataSource = ds2
                dl2.DataTextField = "Status_Desc_En"
                dl2.DataValueField = "Status"
                dl2.DataBind()
                Dim str2 As String = CType(e.Item.FindControl("Level_Status_L"), Label).Text
                dl2.SelectedIndex = dl1.Items.IndexOf(dl1.Items.FindByText(str2))
            Else
                If e.Item.ItemIndex <> -1 Then
                    e.Item.Cells(0).Text = Live.ClassSystem.LiveSystem.GetLevelCodeStatusByMenuID(e.Item.Cells(1).Text).Tables(0).Rows(0).Item("Level_Name").ToString
                    e.Item.Cells(4).Text = Live.ClassSystem.LiveSystem.GetLevelCodeStatusByMenuID(e.Item.Cells(1).Text).Tables(0).Rows(0).Item("Status_Desc_En").ToString
                End If
            End If
 
 
        End Sub
 
    End Class
 
 
End Namespace
 

 Note:

Result:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值