Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles GridView1.SelectedIndexChanged
' Get the currently selected row using the SelectedRow property.
' From Debug mode, I can see that the SelectedRow is obtaining the chosen row
' RowIndex = 7; ID = ctl09; SelectedRows.Cells.Count = 12, but Cells are dispaying empty
Dim row As GridViewRow = GridView1.SelectedRow
Dim index As Integer = GridView1.SelectedIndex
Dim i As Integer
DetailsView1.Caption = "Details View for " & GridView1.SelectedDataKey.Values("SMFID") & " "
'Although the index value is correct and SelectedDataKey value is fine,
'Cells are empty, but they should contain actual data from Grid View
'Output from the following is "Details View for 17XX ;;;;;;;;;;"
For i = 1 To 10
'DetailsView1.Caption &= GridView1.SelectedRow.Cells(i).Text & ";"
'DetailsView1.Caption &= GridView1.Rows(index).Cells(i).Text & ";"
DetailsView1.Caption &= row.Cells(i).Text & ";"
Next i
--------------------------------
<asp:GridView ID="GridView1" runat="server"
AllowPaging="True"
AllowSorting="True"
AutoGenerateColumns="False"
DataKeyNames="SMFID"
DataSourceID="SqlDataSource1"
EmptyDataText="There are no data records to display.">
<Columns>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server"
CausesValidation="True"
CommandName="Update" Text="Update">
</asp:LinkButton> <asp:LinkButton
ID="LinkButton2" runat="server"
CausesValidation="False"
CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server"
CausesValidation="False" CommandName="Edit" Text="Edit">
</asp:LinkButton> <asp:LinkButton
ID="LinkButton2" runat="server" CausesValidation="False"
OnClientClick="return confirm('Are you sure you want to DELETE this record?');"
CommandName="Delete" Text="Delete">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField CommandName="Select" DataTextField="SMFID"
HeaderText="SMFID" ShowHeader="True" SortExpression="SMFID" />
<asp:TemplateField HeaderText="SMS" SortExpression="SMS">
<EditItemTemplate>
<asp:TextBox ID="txtSMS" runat="server"
Columns="5" MaxLength="10"
Text='<%# Bind("SMS") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldSMS"
runat="server"
ErrorMessage="Please enter SMS"
ControlToValidate="txtSMS"
Display="Dynamic"
SetFocusOnError="True">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("SMS") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="JESMAS" SortExpression="JESMAS">
<EditItemTemplate>
<asp:TextBox ID="txtJESMAS" runat="server" MaxLength="30"
Text='<%# Bind("JESMAS") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldJESMAS"
runat="server"
ErrorMessage="Please enter JESMAS"
ControlToValidate="txtJESMAS"
Display="Dynamic"
SetFocusOnError="True">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("JESMAS") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
:
|