1

当TemplateColumn的行发生变化(asp:radiobuttonlist)时获取DataGrid的行索引

<asp:DataGrid ID="dgTier2" runat="server" AutoGenerateColumns="False" Width="578px" 
     Height="83px" OnItemDataBound="dgTier2_ItemDataBound">
    <asp:BoundColumn  DataField="TypeID" HeaderText="TypeID">
    </asp:BoundColumn>
    <asp:BoundColumn  DataField="Type" HeaderText="Category Type">
    </asp:BoundColumn>
     <asp:TemplateColumn HeaderText="Manual Tracking Option" >
      <ItemStyle VerticalAlign="Bottom" />
       <itemtemplate>
        <asp:radiobuttonlist id="rdbtnManual" runat="server" on RepeatDirection="Horizontal">
        <asp:listitem id="M"  runat="server" Text="Manual" Value="1" />
        <asp:listitem id="A"  runat="server" Text="NoManual" Value="0" />
     </asp:radiobuttonlist>
     </itemtemplate>
     </asp:TemplateColumn>
     </asp:DataGrid>

在更改 rediobutton 选择以获取更改行的 Rowindex 之后。如果在许多行中发生了所有更改,我需要收集 Rowindexs。这是否可行?

4

1 回答 1

1

我的答案..

我在 itemtemplate 列中添加了 OnSelectedIndexChanged 属性。

<asp:TemplateColumn HeaderText="Manual Tracking Option">
    <ItemStyle VerticalAlign="Bottom" />
    <itemtemplate>
    <asp:radiobuttonlist id="rdbtnManual" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ManTracChanged" RepeatDirection="Horizontal">
    <asp:listitem id="M"  runat="server" Text="Manual" Value="1" />
    <asp:listitem id="A"  runat="server" Text="No Manual" Value="0" />
    </asp:radiobuttonlist>
    </itemtemplate>
</asp:TemplateColumn>

在后面的代码中

  'for storing list of RowIndex which change occur  
  Private objListManTrack As New List(Of Integer) 

  Protected Sub ManTracChanged(ByVal sender As Object, ByVal e As EventArgs)
       Dim RowIndex As Integer = Nothing
       Dim rblist As RadioButtonList
       rblist = CType(sender, RadioButtonList)
       Dim modifiedgriditem As DataGridItem = CType(rblist.Parent.Parent, DataGridItem)
       RowIndex = modifiedgriditem.ItemIndex

        If Session("objListManTrack") Is Nothing Then
            objListManTrack.Add(RowIndex)
            Session("objListManTrack") = objListManTrack
        Else
            objListManTrack = Session("objListManTrack")
            objListManTrack.Add(RowIndex)
            Session("objListManTrack") = objListManTrack

        End If

End Sub

在函数中,我正在制作发生变化的网格行的索引列表。

最后获得更新行的列表,然后我们可以在一个按钮单击事件中反映对 DB 的更改......

于 2012-04-21T13:25:07.853 回答