问题
To get the row index of DataGrid when change(asp:radiobuttonlist) occur in row of the TemplateColumn
<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>
After changing the rediobutton selection to get the Rowindex of the changed row.If at all change happens in many rows I need make the collection of the Rowindexs.Is that passible?
回答1:
My answer..
I have add the OnSelectedIndexChanged property in itemtemplate column.
<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>
in code behind
'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
in function i am making the list of index Of the Grid Rows which got changes.
finaly get the list of updated rows then we can reflect the changes to DB in one Button click event....
来源:https://stackoverflow.com/questions/10247048/datagrid-templatecolumn-triger-an-event-when-changes-occuredaspradiobuttonli