Datakeys fetching Null values

Hi all,
I have posting this question from past week. i hope to get Answers today. i have had a good discussion with one of masters...but still hanging low..Refer the link below for the question
http://www.experts-exchange.com/Programming/Languages/Q_23886558.html#a22935029
Please help!!!!
LVL 1
SaraDobAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

madhevan_pillaiCommented:
Hi

try this sample code

aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="DataGrid.aspx.vb" Inherits="Data_DataGrid" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:GridView ID="GrdLocation" runat="server"
DataKeyNames="LocId,Location"
autogeneratecolumns="false" AutoGenerateSelectButton="True"
onselectedindexchanging="GrdLocation_SelectedIndexChanging" AllowPaging="True"
AllowSorting="True">
<columns>
<asp:commandfield showselectbutton="true"
headertext="Select Location"/>
<asp:boundfield datafield="LocId"
headertext="LocId"/>
<asp:boundfield datafield="Location"
headertext="Location"/>
<asp:boundfield datafield="City"
headertext="City"/>
<asp:boundfield datafield="State"
headertext="State"/>
<asp:boundfield datafield="Country"
headertext="Country"/>
</columns>
 
</asp:GridView>
        <asp:TextBox ID="TextBox1" runat="server" Width="489px"></asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    </form>
</body>
</html>


code behind


Partial Class Data_DataGrid
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (Not Me.IsPostBack) Then
            Me.GrdLocation.DataSource = clsData.GetDataTable
            Me.GrdLocation.DataBind()
        End If
    End Sub

    Protected Sub GrdLocation_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles GrdLocation.SelectedIndexChanging
        Dim gid As Guid = CType(Me.GrdLocation.DataKeys(e.NewSelectedIndex)("LocId"), Guid)
        Me.TextBox1.Text = gid.ToString
        Me.TextBox2.Text = Me.GrdLocation.DataKeys(e.NewSelectedIndex)("Location").ToString


    End Sub
End Class



app_code


Imports System.Data

Public Class clsData
    Public Shared Function GetDataTable() As DataTable
        Dim dt As New DataTable
        dt.Columns.Add("LocId", GetType(Guid))
        dt.Columns.Add("Location")
        dt.Columns.Add("City")
        dt.Columns.Add("State")
        dt.Columns.Add("Country")

        dt.Rows.Add(New Object() {System.Guid.NewGuid, "aaaaa", "aaaaaaaaa", "aaaaaaaaaaaa", "aaaaaaaaaaaa"})
        dt.Rows.Add(New Object() {System.Guid.NewGuid, "bbbbb", "bbbbbbbbb", "bbbbbbbbbbbb", "bbbbbbbbbbbb"})
        dt.Rows.Add(New Object() {System.Guid.NewGuid, "ccccc", "ccccccccc", "cccccccccccc", "cccccccccccc"})
        dt.Rows.Add(New Object() {System.Guid.NewGuid, "ddddd", "ddddddddd", "dddddddddddd", "dddddddddddd"})

        Return dt
    End Function


    Public Shared Function GetDataTable1() As DataTable
        Dim dt As New DataTable
        dt.Columns.Add("LocId")
        dt.Columns.Add("Location")
        dt.Columns.Add("City")
        dt.Columns.Add("State")
        dt.Columns.Add("Country")

        dt.Rows.Add(New Object() {1, "aaaaa", "aaaaaaaaa", "aaaaaaaaaaaa", "aaaaaaaaaaaa"})
        dt.Rows.Add(New Object() {2, "bbbbb", "bbbbbbbbb", "bbbbbbbbbbbb", "bbbbbbbbbbbb"})
        dt.Rows.Add(New Object() {3, "ccccc", "ccccccccc", "cccccccccccc", "cccccccccccc"})
        dt.Rows.Add(New Object() {4, "ddddd", "ddddddddd", "dddddddddddd", "dddddddddddd"})

        Return dt
    End Function

End Class
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
madhevan_pillaiCommented:
please see this in ur code

    Dim LocId As Guid = CType(Me.GrdLocation.DataKeys(e.NewSelectedIndex)("LocID"),

 <asp:boundfield datafield="LocId"  headertext="LocId"/>

see the LocID case with LocId
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.