Question : Can't obtain cell values from Selected Row of GridView programmatically

Although I am using standard methods to try to obtain cell values from the Selected Row within a GridView, the Cells appear empty. From Debug mode, all other attributes of the GridView and SelectedRow are fine (and there are values in all cells displayed in the Browser).

I've included the GridView1_SelectedIndexChanged method and the first part of the Templated GridView1. The other 10 fields are similar to the JESMAS field content.

Why can't I get the actual values of the cells for the selected row? Better yet, how can I make the code work so that I can get the actual values of the cells?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
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>&nbsp;<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>&nbsp;<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>
            :

Answer : Can't obtain cell values from Selected Row of GridView programmatically

aix is an os - the shell is just a command line (like the dos style cmd or the powershell in windows) - likely known as bash
Random Solutions  
 
programming4us programming4us