【问题标题】:Access datagrid controls in a dropdown list selectedindexchanged event访问下拉列表中的数据网格控件 selectedindexchanged 事件
【发布时间】:2013-01-31 14:22:22
【问题描述】:

HTML 代码:

<cc1:SPASDataGrid ID="dgPayments" runat="server" AutoGenerateColumns="false" ShowFooter="true" Ajaxify="true">
    <EditItemStyle VerticalAlign="Top"></EditItemStyle>
    <FooterStyle VerticalAlign="Top"></FooterStyle>
    <Columns>
          <asp:TemplateColumn HeaderText="Pay To">
            <FooterTemplate>
                <table id="Table3" runat="server">
                                               <tr>
                    <td>
                                                      <uc1:AnyDropDown ID="ddRolloverSource" runat="server" TableName="system_code" DisplayFieldName="description" CodeFieldName="code_value" WhereClause="PAYROLL_REQUEST" OnSelectedIndexChanged="ddRolloverSource_SelectedIndexChanged" AutoPostBack="true"></uc1:AnyDropDown>
                                                  </td>
                     </tr>
                                        </table>
            </FooterTemplate>
                              <ItemTemplate></ItemTemplate>
                              <EditItemTemplate></EditItemTemplate>
             </asp:TemplateColumn>
             <asp:TemplateColumn HeaderText="Post Tax Amount">
            <FooterTemplate>
                                      <table>
                <tr>
                   <td>
                    <cc1:SPASRadioButton Checked="true" Text="All" ID="rbPostTaxAll" GroupName="rbPostTaxAllOrRemaining" TabIndex="40" runat="server" CssClass="CheckBoxList"></cc1:SPASRadioButton>
                                           </td>
                   <td >
                    <cc1:SPASDropDownList ID="ddlPostTaxAmountOrPercentageF"  TabIndex="80" runat="server">
                    <asp:ListItem Selected="true" Value="Amount">Amount</asp:ListItem>
                    </cc1:SPASDropDownList>
                                           </td>                                        </tr>
                  </table>
            </FooterTemplate>
                              <ItemTemplate></ItemTemplate>                                    <EditItemTemplate></EditItemTemplate>                                                            
</Columns>
</cc1:SPASDataGrid>

代码隐藏:

Protected Sub ddRolloverSource_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
'Disable the rbPostTaxAll and ddlPostTaxAmountOrPercentageF controls
 End Sub

我正在尝试访问下拉列表的 selectedIndexChanged 事件中 Datagrid 中的控件,该下拉列表也在 Datagrid 中。

【问题讨论】:

    标签: vb.net datagrid selectedindexchanged


    【解决方案1】:

    如果您使用的是普通的 GridView,那么您就是这样做的。 您只需要在每一行中找到该控件,然后您就可以禁用它

    Protected Sub ddRolloverSource_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        For Each myDR As GridViewRow In GridView1.Rows
          If myDR.RowType=GridViewRowType.DataRow Then
            Dim FoundRadioButton As RadioButton = DirectCast(myDR.FindControl("rbPostTaxAll"), RadioButton)
            Dim FoundDropDownList As DropDownList = DirectCast(myDR.FindControl("ddlPostTaxAmountOrPercentageF"), DropDownList)
            FoundRadioButton.Enabled = False
            FoundDropDownList.Enabled = False
          End If  
        Next
    End Sub
    

    编辑添加了比尔的建议

    编辑为 DataGrid 添加了解决方案

    DataGrid 使用这个

    Protected Sub ddRolloverSource_SelectedIndexChanged(sender As Object, e As EventArgs)
    
        Dim RowCount As Integer = DataGrid1.Items.Count - 1
        For i As Integer = 0 To RowCount - 1
            Dim RowItem As DataGridItem = DataGrid1.Items(RowCount)
            Dim FoundRadioButton As RadioButton = DirectCast(RowItem.FindControl("rbPostTaxAll"), RadioButton)
            Dim FoundDropDownList As DropDownList = DirectCast(RowItem.FindControl("ddlPostTaxAmountOrPercentageF"), DropDownList)
    
            FoundRadioButton.Enabled = False
            FoundDropDownList.Enabled = False
        Next
    End Sub
    

    【讨论】:

    • 我会添加一个 RowType 测试。语法接近:“If myDR.RowType=GridViewRowType.DataRow Then”
    • @Raymund:这是 DataGrid 而不是 GridView。
    • @Raymund - 我在 ddRolloverSource_SelectedIndexChanged 事件中得到 DataGrid1.Items.Count = 0。
    • 尝试用这个“Dim RowCount As Integer = DataGrid1.BindingContext(DataGrid1.DataSource).Count”替换“DataGrid1.Items.Count”
    • @Raymund - 错误:BindingContext 不是 DataGrid 的成员。
    【解决方案2】:

    终于找到解决办法了。

    Protected Sub ddRolloverSource_SelectedIndexChanged(sender As Object, e As EventArgs)
            Dim tbl As Table = DirectCast(dgPayments.Controls(0), Table)
            Dim footer As DataGridItem = DirectCast(tbl.Controls(tbl.Controls.Count - 1), DataGridItem)
            Dim rbPostTaxAll As RadioButton = DirectCast(footer.FindControl("rbPostTaxAll"), RadioButton )
            Dim rbPostTaxRemaining As DropDownList = DirectCast(footer.FindControl("rbPostTaxRemaining"), DropDownList )
    
            rbPostTaxAll .Enabled = False
            rbPostTaxRemaining .Enabled = False       
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-06
      • 2023-04-03
      相关资源
      最近更新 更多