2013-02-15 73 views
2

HTML代码:访问的DataGrid控件SelectedIndexChanged事件

<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中。

回答

0

终于找到了s olution。

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 
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 
+2

我会添加一个RowType测试。语法接近于:“如果myDR.RowType = GridViewRowType.DataRow Then” – Bill 2013-02-18 23:26:32

+0

@ Raymond:这是一个DataGrid,而不是一个GridView。 – 2013-02-19 15:58:13

+0

@ComputerGeek - 我用DataGrid更新了答案 – Raymund 2013-02-19 19:56:58

相关问题