如何在gridview中添加级联下拉列表以进行编辑?

时间:2021-11-21 03:12:54

I have a fairly standard ASP.NET GridView that displays 2 columns that have a parent child relationship. Although the relationship exists in the database between column A and column B, the GridView does not implement it.

我有一个相当标准的ASP.NET GridView,它显示了2列具有父子关系的列。尽管在A列和B列之间的数据库中存在关系,但GridView不实现它。

I would like to do the following: When the user has elected to edit the row, 2 dropdown menus become visible. The DropDownB should automatically be populated with the available options based upon DropDownA's value. When DropDownA changes, DropDownB needs to be updated to reflect the current options.

我想执行以下操作:当用户选择编辑行时,会显示2个下拉菜单。 DropDownB应根据DropDownA的值自动填充可用选项。 DropDownA更改时,需要更新DropDownB以反映当前选项。

Columns currently available to the grid:

当前可用于网格的列:

 - ColumnAID
 - ColumnADescription
 - ColumnBID
 - ColumnBDescription

I can certainly accomplish this same functionality outside of the grid, could even have a selected row event display a modal popup allowing me to edit the fields accordingly, but would like to keep this contained to the grid.

我当然可以在网格之外完成相同的功能,甚至可以让选定的行事件显示模态弹出窗口,允许我相应地编辑字段,但是希望将其包含在网格中。

3 个解决方案

#1


This is how you should so It.

这就是你应该这样做的。

1.) Goto Column editor of the GridView. And convert the Column to Template which you want to display the DropDownList instead of the TextBox.

1.)转到GridView的列编辑器。并将列转换为模板,您要显示DropDownList而不是TextBox。

2.) Goto GridView SmartTag and select the Option to Edit Templates. Select the Column you converted into Template in GridView Column Editor.

2.)转到GridView SmartTag并选择编辑模板选项。在GridView列编辑器中选择您转换为模板的列。

3.) This Column will have the Template for all the Views. Select the Edit view. This will already have TextBox there.

3.)此列将包含所有视图的模板。选择“编辑”视图。这已经有了TextBox。

4.) Remove the TxtBox and put a DropDownList there. You need to configure the DropDownList to populate the data from Foreign Table by using ObjectDataSource or SqlDataSource. The Value prop. of the DropDownList should be set to P.Key of the ForeginTable.

4.)删除TxtBox并在其中放置DropDownList。您需要配置DropDownList以使用ObjectDataSource或SqlDataSource填充来自Foreign Table的数据。价值道具。应该将DropDownList的值设置为ForeginTable的P.Key。

5.) Now, bind the SelectedValue field to the Foregin Key in your table. If you use Bind it will perform Two-Way binding to Read/Write, If you use Eval it will perform OneWay binding to Read and set the default value only.

5.)现在,将SelectedValue字段绑定到表中的Foregin Key。如果使用Bind,它将执行双向绑定到读/写,如果使用Eval,它将执行OneWay绑定到Read并仅设置默认值。

For more info visit this link.

有关更多信息,请访问此链接。

LinkTxt: http://www.asp.net/learn/data-access/tutorial-20-cs.aspx

Thanks.

hope this helps.

希望这可以帮助。

#2


The below examples show 2 dropdowns Holiday group and Holiday Type. Based on the selection of Holiday Group, the holiday type dropdown will be loaded. The catch here is the Auto Postback set to "true" and define the event for selectindex change of the first dropdown OnSelectedIndexChanged="CboHolidayGroup_SelectedIndexChanged"
Replace the "(" and ")" with "<" and ">" respectively.
The below code can be used for cascading dropdowns inside a grid view:

以下示例显示了2个下拉假期组和假日类型。根据Holiday Group的选择,将加载假日类型下拉列表。这里的捕获是Auto Postback设置为“true”并定义第一个下拉列表的selectindex更改事件OnSelectedIndexChanged =“CboHolidayGroup_SelectedIndexChanged”分别用“<”和“>”替换“(”和“)”。以下代码可用于网格视图中的级联下拉列表:

Design page

(asp:TemplateField HeaderText="(*) Holiday Group")
    (ItemStyle CssClass="TEXTBOX_MEDIUM" /)
    (EditItemTemplate)
        (asp:DropDownList ID="CboHolidayGroup" CssClass="DROPDOWN_SMALL" runat="server"
            DataTextField="holidaygroup" DataValueField="holiday_group_code_id" AutoPostBack="true"
            OnSelectedIndexChanged="CboHolidayGroup_SelectedIndexChanged")
        (/asp:DropDownList)
        (asp:RangeValidator ID="RvHolidayGroup" runat="server" ControlToValidate="CboHolidayGroup"
            Display="None" ErrorMessage="Please Select Holiday Group" MaximumValue="1000"
            MinimumValue="1" SetFocusOnError="true" Type="Integer" ValidationGroup="VgrpUpdate")
        (/asp:RangeValidator)
    (/EditItemTemplate)
    (ItemTemplate)
        (asp:Label ID="LblHolidayGroup" CssClass="DROPDOWN_SMALL" runat="server" Text='<%# Eval("holidaygroup") %>')(/asp:Label)
    (/ItemTemplate)
    (FooterTemplate)
        (asp:DropDownList ID="CboNewHolidayGroup" CssClass="DROPDOWN_SMALL" runat="server"
            DataTextField="holidaygroup" DataValueField="holiday_group_code_id" Enabled="false"
            AutoPostBack="true" OnSelectedIndexChanged="CboHolidayGroup_SelectedIndexChanged")
        (/asp:DropDownList)
        (asp:RangeValidator ID="RvNewHolidayGroup" runat="server" ControlToValidate="CboNewHolidayGroup"
            Display="None" ErrorMessage="Please Select Holiday Group" MaximumValue="1000"
            MinimumValue="1" SetFocusOnError="true" Type="Integer" ValidationGroup="VgrpInsert")
        (/asp:RangeValidator)
    (/FooterTemplate)
(/asp:TemplateField)
(asp:TemplateField HeaderText="(*) Holiday Type")
    (ItemStyle CssClass="DROPDOWN_XLARGE" /)
    (EditItemTemplate)
        (asp:DropDownList ID="CboHolidayType" CssClass="DROPDOWN_XLARGE" runat="server"
            DataTextField="holidaytype" DataValueField="holiday_type_code_id")
        (/asp:DropDownList)
        (asp:RangeValidator ID="RvHolidayType" runat="server" ControlToValidate="CboHolidayType"
            Display="None" ErrorMessage="Please Select Holiday Type" MaximumValue="1000"
            MinimumValue="1" SetFocusOnError="true" Type="Integer" ValidationGroup="VgrpUpdate")
        (/asp:RangeValidator)
    (/EditItemTemplate)
    (ItemTemplate)
        (asp:Label ID="LblHolidayType" CssClass="DROPDOWN_XLARGE" runat="server" Text='<%# Eval("holidaytype") %>')(/asp:Label)
    (/ItemTemplate)
    (FooterTemplate)
        (asp:DropDownList ID="CboNewHolidayType" CssClass="DROPDOWN_XLARGE" runat="server"
            DataTextField="holidaytype" DataValueField="holiday_type_code_id" Enabled="false")
        (/asp:DropDownList)
        (asp:RangeValidator ID="RvNewHolidayType" runat="server" ControlToValidate="CboNewHolidayType"
            Display="None" ErrorMessage="Please Select Holiday Type" MaximumValue="1000"
            MinimumValue="1" SetFocusOnError="true" Type="Integer" ValidationGroup="VgrpInsert")
        (/asp:RangeValidator)
    (/FooterTemplate)
(/asp:TemplateField)

Code Behind and Design

代码背后和设计

<asp:TemplateField HeaderText="(*) Holiday Group">
    <ItemStyle CssClass="TEXTBOX_MEDIUM" />
    <EditItemTemplate>
        <asp:DropDownList ID="CboHolidayGroup" CssClass="DROPDOWN_SMALL" runat="server"
            DataTextField="holidaygroup" DataValueField="holiday_group_code_id" AutoPostBack="true"
            OnSelectedIndexChanged="CboHolidayGroup_SelectedIndexChanged">
        </asp:DropDownList>
        <asp:RangeValidator ID="RvHolidayGroup" runat="server" ControlToValidate="CboHolidayGroup"
            Display="None" ErrorMessage="Please Select Holiday Group" MaximumValue="1000"
            MinimumValue="1" SetFocusOnError="true" Type="Integer" ValidationGroup="VgrpUpdate">
        </asp:RangeValidator>
    </EditItemTemplate>
    <ItemTemplate>
        <asp:Label ID="LblHolidayGroup" CssClass="DROPDOWN_SMALL" runat="server" Text='<%# Eval("holidaygroup") %>'></asp:Label>
    </ItemTemplate>
    <FooterTemplate>
        <asp:DropDownList ID="CboNewHolidayGroup" CssClass="DROPDOWN_SMALL" runat="server"
            DataTextField="holidaygroup" DataValueField="holiday_group_code_id" Enabled="false"
            AutoPostBack="true" OnSelectedIndexChanged="CboHolidayGroup_SelectedIndexChanged">
        </asp:DropDownList>
        <asp:RangeValidator ID="RvNewHolidayGroup" runat="server" ControlToValidate="CboNewHolidayGroup"
            Display="None" ErrorMessage="Please Select Holiday Group" MaximumValue="1000"
            MinimumValue="1" SetFocusOnError="true" Type="Integer" ValidationGroup="VgrpInsert">
        </asp:RangeValidator>
    </FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="(*) Holiday Type">
    <ItemStyle CssClass="DROPDOWN_XLARGE" />
    <EditItemTemplate>
        <asp:DropDownList ID="CboHolidayType" CssClass="DROPDOWN_XLARGE" runat="server" DataTextField="holidaytype"
            DataValueField="holiday_type_code_id">
        </asp:DropDownList>
        <asp:RangeValidator ID="RvHolidayType" runat="server" ControlToValidate="CboHolidayType"
            Display="None" ErrorMessage="Please Select Holiday Type" MaximumValue="1000"
            MinimumValue="1" SetFocusOnError="true" Type="Integer" ValidationGroup="VgrpUpdate">
        </asp:RangeValidator>
    </EditItemTemplate>
    <ItemTemplate>
        <asp:Label ID="LblHolidayType" CssClass="DROPDOWN_XLARGE" runat="server" Text='<%# Eval("holidaytype") %>'></asp:Label>
    </ItemTemplate>
    <FooterTemplate>
        <asp:DropDownList ID="CboNewHolidayType" CssClass="DROPDOWN_XLARGE" runat="server"
            DataTextField="holidaytype" DataValueField="holiday_type_code_id" Enabled="false">
        </asp:DropDownList>
        <asp:RangeValidator ID="RvNewHolidayType" runat="server" ControlToValidate="CboNewHolidayType"
            Display="None" ErrorMessage="Please Select Holiday Type" MaximumValue="1000"
            MinimumValue="1" SetFocusOnError="true" Type="Integer" ValidationGroup="VgrpInsert">
        </asp:RangeValidator>
    </FooterTemplate>
</asp:TemplateField>

.

#Region "CboHolidayGroup_SelectedIndexChanged"
Protected Sub CboHolidayGroup_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
    Dim sGroup As String = String.Empty
    Dim intGroup As Integer = 0
    Dim dtNewHolidayType As DataTable
    Dim dtHolidayType As DataTable
    Dim objAims As iSymbol = Factory.Factory.CreateSymbolObject()

    If DirectCast(sender, DropDownList).SelectedIndex > 0 Then
        If Not IsNothing(DirectCast(sender, DropDownList).Parent.FindControl("CboHolidayGroup")) Then
            sGroup = DirectCast(sender, DropDownList).SelectedItem.Text
            intGroup = DirectCast(sender, DropDownList).SelectedValue
            If sGroup = "Bank" Then
                If Not IsNothing(DirectCast(sender, DropDownList).Parent.FindControl("ChkBankHoliday")) Then
                    DirectCast(DirectCast(sender, DropDownList).Parent.FindControl("ChkBankHoliday"), CheckBox).Checked = True
                End If

                If Not IsNothing(DirectCast(sender, DropDownList).Parent.FindControl("ChkNewBankHoliday")) Then
                    DirectCast(DirectCast(sender, DropDownList).Parent.FindControl("ChkNewBankHoliday"), CheckBox).Checked = True
                End If
            Else
                If Not IsNothing(DirectCast(sender, DropDownList).Parent.FindControl("ChkBankHoliday")) Then
                    DirectCast(DirectCast(sender, DropDownList).Parent.FindControl("ChkBankHoliday"), CheckBox).Checked = False
                End If

                If Not IsNothing(DirectCast(sender, DropDownList).Parent.FindControl("ChkNewBankHoliday")) Then
                    DirectCast(DirectCast(sender, DropDownList).Parent.FindControl("ChkNewBankHoliday"), CheckBox).Checked = False
                End If
            End If

            If Not IsNothing(DirectCast(sender, DropDownList).Parent.FindControl("CboHolidayType")) Then
                Dim CboHolidayType As DropDownList = DirectCast(DirectCast(sender, DropDownList).Parent.FindControl("CboHolidayType"), DropDownList)
                dtHolidayType = objSymbol.GetSelectedHolTypes(intGroup)
                If (dtHolidayType.Rows.Count > 0) Then
                    CboHolidayType.DataSource = dtHolidayType
                    CboHolidayType.DataTextField = "holidaytype"
                    CboHolidayType.DataValueField = "holiday_type_code_id"
                    CboHolidayType.DataBind()
                    AddFirstItem(CboHolidayType, _CON_COMBO_FIRST_SELECT)
                End If
            End If
        End If

        If Not IsNothing(DirectCast(sender, DropDownList).Parent.FindControl("CboNewHolidayGroup")) Then
            sGroup = DirectCast(sender, DropDownList).SelectedItem.Text
            intGroup = DirectCast(sender, DropDownList).SelectedValue
            If sGroup = "Bank" Then
                If Not IsNothing(DirectCast(sender, DropDownList).Parent.FindControl("ChkNewBankHoliday")) Then
                    DirectCast(DirectCast(sender, DropDownList).Parent.FindControl("ChkNewBankHoliday"), CheckBox).Checked = True
                End If
            Else
                If Not IsNothing(DirectCast(sender, DropDownList).Parent.FindControl("ChkNewBankHoliday")) Then
                    DirectCast(DirectCast(sender, DropDownList).Parent.FindControl("ChkNewBankHoliday"), CheckBox).Checked = False
                End If
            End If

            If Not IsNothing(DirectCast(sender, DropDownList).Parent.FindControl("CboNewHolidayType")) Then
                Dim CboNewHolidayType As DropDownList = DirectCast(DirectCast(sender, DropDownList).Parent.FindControl("CboNewHolidayType"), DropDownList)
                dtHolidayType = objSymbol.GetSelectedHolTypes(intGroup)
                If (dtHolidayType.Rows.Count > 0) Then
                    CboNewHolidayType.DataSource = dtHolidayType
                    CboNewHolidayType.DataTextField = "holidaytype"
                    CboNewHolidayType.DataValueField = "holiday_type_code_id"
                    CboNewHolidayType.DataBind()
                    AddFirstItem(CboNewHolidayType, _CON_COMBO_FIRST_SELECT)
                End If                    
            End If
        End If
    End If
End Sub
#End Region

#3


A partial answer is that DataSources have a scope. If you create them inside of a template, they only exist for that template. If you make them dependent on each other and in the same scope, they should cascade.

部分答案是DataSources有一个范围。如果您在模板内创建它们,则它们仅对该模板存在。如果你使它们彼此依赖并且在相同的范围内,它们应该级联。

#1


This is how you should so It.

这就是你应该这样做的。

1.) Goto Column editor of the GridView. And convert the Column to Template which you want to display the DropDownList instead of the TextBox.

1.)转到GridView的列编辑器。并将列转换为模板,您要显示DropDownList而不是TextBox。

2.) Goto GridView SmartTag and select the Option to Edit Templates. Select the Column you converted into Template in GridView Column Editor.

2.)转到GridView SmartTag并选择编辑模板选项。在GridView列编辑器中选择您转换为模板的列。

3.) This Column will have the Template for all the Views. Select the Edit view. This will already have TextBox there.

3.)此列将包含所有视图的模板。选择“编辑”视图。这已经有了TextBox。

4.) Remove the TxtBox and put a DropDownList there. You need to configure the DropDownList to populate the data from Foreign Table by using ObjectDataSource or SqlDataSource. The Value prop. of the DropDownList should be set to P.Key of the ForeginTable.

4.)删除TxtBox并在其中放置DropDownList。您需要配置DropDownList以使用ObjectDataSource或SqlDataSource填充来自Foreign Table的数据。价值道具。应该将DropDownList的值设置为ForeginTable的P.Key。

5.) Now, bind the SelectedValue field to the Foregin Key in your table. If you use Bind it will perform Two-Way binding to Read/Write, If you use Eval it will perform OneWay binding to Read and set the default value only.

5.)现在,将SelectedValue字段绑定到表中的Foregin Key。如果使用Bind,它将执行双向绑定到读/写,如果使用Eval,它将执行OneWay绑定到Read并仅设置默认值。

For more info visit this link.

有关更多信息,请访问此链接。

LinkTxt: http://www.asp.net/learn/data-access/tutorial-20-cs.aspx

Thanks.

hope this helps.

希望这可以帮助。

#2


The below examples show 2 dropdowns Holiday group and Holiday Type. Based on the selection of Holiday Group, the holiday type dropdown will be loaded. The catch here is the Auto Postback set to "true" and define the event for selectindex change of the first dropdown OnSelectedIndexChanged="CboHolidayGroup_SelectedIndexChanged"
Replace the "(" and ")" with "<" and ">" respectively.
The below code can be used for cascading dropdowns inside a grid view:

以下示例显示了2个下拉假期组和假日类型。根据Holiday Group的选择,将加载假日类型下拉列表。这里的捕获是Auto Postback设置为“true”并定义第一个下拉列表的selectindex更改事件OnSelectedIndexChanged =“CboHolidayGroup_SelectedIndexChanged”分别用“<”和“>”替换“(”和“)”。以下代码可用于网格视图中的级联下拉列表:

Design page

(asp:TemplateField HeaderText="(*) Holiday Group")
    (ItemStyle CssClass="TEXTBOX_MEDIUM" /)
    (EditItemTemplate)
        (asp:DropDownList ID="CboHolidayGroup" CssClass="DROPDOWN_SMALL" runat="server"
            DataTextField="holidaygroup" DataValueField="holiday_group_code_id" AutoPostBack="true"
            OnSelectedIndexChanged="CboHolidayGroup_SelectedIndexChanged")
        (/asp:DropDownList)
        (asp:RangeValidator ID="RvHolidayGroup" runat="server" ControlToValidate="CboHolidayGroup"
            Display="None" ErrorMessage="Please Select Holiday Group" MaximumValue="1000"
            MinimumValue="1" SetFocusOnError="true" Type="Integer" ValidationGroup="VgrpUpdate")
        (/asp:RangeValidator)
    (/EditItemTemplate)
    (ItemTemplate)
        (asp:Label ID="LblHolidayGroup" CssClass="DROPDOWN_SMALL" runat="server" Text='<%# Eval("holidaygroup") %>')(/asp:Label)
    (/ItemTemplate)
    (FooterTemplate)
        (asp:DropDownList ID="CboNewHolidayGroup" CssClass="DROPDOWN_SMALL" runat="server"
            DataTextField="holidaygroup" DataValueField="holiday_group_code_id" Enabled="false"
            AutoPostBack="true" OnSelectedIndexChanged="CboHolidayGroup_SelectedIndexChanged")
        (/asp:DropDownList)
        (asp:RangeValidator ID="RvNewHolidayGroup" runat="server" ControlToValidate="CboNewHolidayGroup"
            Display="None" ErrorMessage="Please Select Holiday Group" MaximumValue="1000"
            MinimumValue="1" SetFocusOnError="true" Type="Integer" ValidationGroup="VgrpInsert")
        (/asp:RangeValidator)
    (/FooterTemplate)
(/asp:TemplateField)
(asp:TemplateField HeaderText="(*) Holiday Type")
    (ItemStyle CssClass="DROPDOWN_XLARGE" /)
    (EditItemTemplate)
        (asp:DropDownList ID="CboHolidayType" CssClass="DROPDOWN_XLARGE" runat="server"
            DataTextField="holidaytype" DataValueField="holiday_type_code_id")
        (/asp:DropDownList)
        (asp:RangeValidator ID="RvHolidayType" runat="server" ControlToValidate="CboHolidayType"
            Display="None" ErrorMessage="Please Select Holiday Type" MaximumValue="1000"
            MinimumValue="1" SetFocusOnError="true" Type="Integer" ValidationGroup="VgrpUpdate")
        (/asp:RangeValidator)
    (/EditItemTemplate)
    (ItemTemplate)
        (asp:Label ID="LblHolidayType" CssClass="DROPDOWN_XLARGE" runat="server" Text='<%# Eval("holidaytype") %>')(/asp:Label)
    (/ItemTemplate)
    (FooterTemplate)
        (asp:DropDownList ID="CboNewHolidayType" CssClass="DROPDOWN_XLARGE" runat="server"
            DataTextField="holidaytype" DataValueField="holiday_type_code_id" Enabled="false")
        (/asp:DropDownList)
        (asp:RangeValidator ID="RvNewHolidayType" runat="server" ControlToValidate="CboNewHolidayType"
            Display="None" ErrorMessage="Please Select Holiday Type" MaximumValue="1000"
            MinimumValue="1" SetFocusOnError="true" Type="Integer" ValidationGroup="VgrpInsert")
        (/asp:RangeValidator)
    (/FooterTemplate)
(/asp:TemplateField)

Code Behind and Design

代码背后和设计

<asp:TemplateField HeaderText="(*) Holiday Group">
    <ItemStyle CssClass="TEXTBOX_MEDIUM" />
    <EditItemTemplate>
        <asp:DropDownList ID="CboHolidayGroup" CssClass="DROPDOWN_SMALL" runat="server"
            DataTextField="holidaygroup" DataValueField="holiday_group_code_id" AutoPostBack="true"
            OnSelectedIndexChanged="CboHolidayGroup_SelectedIndexChanged">
        </asp:DropDownList>
        <asp:RangeValidator ID="RvHolidayGroup" runat="server" ControlToValidate="CboHolidayGroup"
            Display="None" ErrorMessage="Please Select Holiday Group" MaximumValue="1000"
            MinimumValue="1" SetFocusOnError="true" Type="Integer" ValidationGroup="VgrpUpdate">
        </asp:RangeValidator>
    </EditItemTemplate>
    <ItemTemplate>
        <asp:Label ID="LblHolidayGroup" CssClass="DROPDOWN_SMALL" runat="server" Text='<%# Eval("holidaygroup") %>'></asp:Label>
    </ItemTemplate>
    <FooterTemplate>
        <asp:DropDownList ID="CboNewHolidayGroup" CssClass="DROPDOWN_SMALL" runat="server"
            DataTextField="holidaygroup" DataValueField="holiday_group_code_id" Enabled="false"
            AutoPostBack="true" OnSelectedIndexChanged="CboHolidayGroup_SelectedIndexChanged">
        </asp:DropDownList>
        <asp:RangeValidator ID="RvNewHolidayGroup" runat="server" ControlToValidate="CboNewHolidayGroup"
            Display="None" ErrorMessage="Please Select Holiday Group" MaximumValue="1000"
            MinimumValue="1" SetFocusOnError="true" Type="Integer" ValidationGroup="VgrpInsert">
        </asp:RangeValidator>
    </FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="(*) Holiday Type">
    <ItemStyle CssClass="DROPDOWN_XLARGE" />
    <EditItemTemplate>
        <asp:DropDownList ID="CboHolidayType" CssClass="DROPDOWN_XLARGE" runat="server" DataTextField="holidaytype"
            DataValueField="holiday_type_code_id">
        </asp:DropDownList>
        <asp:RangeValidator ID="RvHolidayType" runat="server" ControlToValidate="CboHolidayType"
            Display="None" ErrorMessage="Please Select Holiday Type" MaximumValue="1000"
            MinimumValue="1" SetFocusOnError="true" Type="Integer" ValidationGroup="VgrpUpdate">
        </asp:RangeValidator>
    </EditItemTemplate>
    <ItemTemplate>
        <asp:Label ID="LblHolidayType" CssClass="DROPDOWN_XLARGE" runat="server" Text='<%# Eval("holidaytype") %>'></asp:Label>
    </ItemTemplate>
    <FooterTemplate>
        <asp:DropDownList ID="CboNewHolidayType" CssClass="DROPDOWN_XLARGE" runat="server"
            DataTextField="holidaytype" DataValueField="holiday_type_code_id" Enabled="false">
        </asp:DropDownList>
        <asp:RangeValidator ID="RvNewHolidayType" runat="server" ControlToValidate="CboNewHolidayType"
            Display="None" ErrorMessage="Please Select Holiday Type" MaximumValue="1000"
            MinimumValue="1" SetFocusOnError="true" Type="Integer" ValidationGroup="VgrpInsert">
        </asp:RangeValidator>
    </FooterTemplate>
</asp:TemplateField>

.

#Region "CboHolidayGroup_SelectedIndexChanged"
Protected Sub CboHolidayGroup_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
    Dim sGroup As String = String.Empty
    Dim intGroup As Integer = 0
    Dim dtNewHolidayType As DataTable
    Dim dtHolidayType As DataTable
    Dim objAims As iSymbol = Factory.Factory.CreateSymbolObject()

    If DirectCast(sender, DropDownList).SelectedIndex > 0 Then
        If Not IsNothing(DirectCast(sender, DropDownList).Parent.FindControl("CboHolidayGroup")) Then
            sGroup = DirectCast(sender, DropDownList).SelectedItem.Text
            intGroup = DirectCast(sender, DropDownList).SelectedValue
            If sGroup = "Bank" Then
                If Not IsNothing(DirectCast(sender, DropDownList).Parent.FindControl("ChkBankHoliday")) Then
                    DirectCast(DirectCast(sender, DropDownList).Parent.FindControl("ChkBankHoliday"), CheckBox).Checked = True
                End If

                If Not IsNothing(DirectCast(sender, DropDownList).Parent.FindControl("ChkNewBankHoliday")) Then
                    DirectCast(DirectCast(sender, DropDownList).Parent.FindControl("ChkNewBankHoliday"), CheckBox).Checked = True
                End If
            Else
                If Not IsNothing(DirectCast(sender, DropDownList).Parent.FindControl("ChkBankHoliday")) Then
                    DirectCast(DirectCast(sender, DropDownList).Parent.FindControl("ChkBankHoliday"), CheckBox).Checked = False
                End If

                If Not IsNothing(DirectCast(sender, DropDownList).Parent.FindControl("ChkNewBankHoliday")) Then
                    DirectCast(DirectCast(sender, DropDownList).Parent.FindControl("ChkNewBankHoliday"), CheckBox).Checked = False
                End If
            End If

            If Not IsNothing(DirectCast(sender, DropDownList).Parent.FindControl("CboHolidayType")) Then
                Dim CboHolidayType As DropDownList = DirectCast(DirectCast(sender, DropDownList).Parent.FindControl("CboHolidayType"), DropDownList)
                dtHolidayType = objSymbol.GetSelectedHolTypes(intGroup)
                If (dtHolidayType.Rows.Count > 0) Then
                    CboHolidayType.DataSource = dtHolidayType
                    CboHolidayType.DataTextField = "holidaytype"
                    CboHolidayType.DataValueField = "holiday_type_code_id"
                    CboHolidayType.DataBind()
                    AddFirstItem(CboHolidayType, _CON_COMBO_FIRST_SELECT)
                End If
            End If
        End If

        If Not IsNothing(DirectCast(sender, DropDownList).Parent.FindControl("CboNewHolidayGroup")) Then
            sGroup = DirectCast(sender, DropDownList).SelectedItem.Text
            intGroup = DirectCast(sender, DropDownList).SelectedValue
            If sGroup = "Bank" Then
                If Not IsNothing(DirectCast(sender, DropDownList).Parent.FindControl("ChkNewBankHoliday")) Then
                    DirectCast(DirectCast(sender, DropDownList).Parent.FindControl("ChkNewBankHoliday"), CheckBox).Checked = True
                End If
            Else
                If Not IsNothing(DirectCast(sender, DropDownList).Parent.FindControl("ChkNewBankHoliday")) Then
                    DirectCast(DirectCast(sender, DropDownList).Parent.FindControl("ChkNewBankHoliday"), CheckBox).Checked = False
                End If
            End If

            If Not IsNothing(DirectCast(sender, DropDownList).Parent.FindControl("CboNewHolidayType")) Then
                Dim CboNewHolidayType As DropDownList = DirectCast(DirectCast(sender, DropDownList).Parent.FindControl("CboNewHolidayType"), DropDownList)
                dtHolidayType = objSymbol.GetSelectedHolTypes(intGroup)
                If (dtHolidayType.Rows.Count > 0) Then
                    CboNewHolidayType.DataSource = dtHolidayType
                    CboNewHolidayType.DataTextField = "holidaytype"
                    CboNewHolidayType.DataValueField = "holiday_type_code_id"
                    CboNewHolidayType.DataBind()
                    AddFirstItem(CboNewHolidayType, _CON_COMBO_FIRST_SELECT)
                End If                    
            End If
        End If
    End If
End Sub
#End Region

#3


A partial answer is that DataSources have a scope. If you create them inside of a template, they only exist for that template. If you make them dependent on each other and in the same scope, they should cascade.

部分答案是DataSources有一个范围。如果您在模板内创建它们,则它们仅对该模板存在。如果你使它们彼此依赖并且在相同的范围内,它们应该级联。