在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.Is的集合是否可以通过?
答案 0 :(得分: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
在函数中我正在制作变更的网格行索引列表。
最后获取更新行列表,然后我们可以在一个Button click事件中反映对DB的更改....