470,615 Members | 2,088 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,615 developers. It's quick & easy.

Problem in reading Values from dybamically added controls

Hi All,

I am not able to read the values from Gridview TemplateField Controls.

basically I craeted a gridview with four colums and finally i added a Template field to it.

The templatefield contains 3 labels and one button while i am clicking on this button. i am getting a error message

Error "Object reference not set to an instance of an object" - .NET VB

Please suggest what should i do for thi problem

this is my Buttons.aspx Page

<%@ Page Language="VB" Debug="true" AutoEventWireup="false" CodeFile="button.aspx.vb" Inherits="button" %>

<!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>Buttons in Gridview</title>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
&nbsp;<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="gid"
DataSourceID="SqlDataSource1" OnSelectedIndexChanged="GridView1_SelectedIndexCha nged">
<asp:BoundField DataField="fn" HeaderText="First Name" SortExpression="fn" />
<asp:BoundField DataField="ln" HeaderText="Last Name" SortExpression="ln" />
<asp:BoundField DataField="email" HeaderText="Email" SortExpression="email" />
<asp:BoundField DataField="regdate" HeaderText="Registered Date" SortExpression="regdate" />
<asp:Label id="fn" runat="server" Text='<%# Eval("fn") %>'></asp:Label><br>
<asp:Label ID="ln" runat="server" Text='<%# Eval("ln") %>'>'></asp:Label><br>
<asp:Label ID="email" runat="server" Text='<%# Eval("email") %>'></asp:Label><br>
<asp:Label ID="rd" runat="server" Text='<%# Eval("regdate") %>'></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Display" CommandName="disp"/>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:My_Connection_String %>"
SelectCommand="SELECT [fn], [ln], [email], [regdate], [gid] FROM [GLogin]"></asp:SqlDataSource>

And This is my code behind file

Imports System.Data.SqlClient
Imports System.Data
Partial Class button
Inherits System.Web.UI.Page

Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs ) Handles GridView1.RowCommand
' Dim dr As DataRow
Dim index As Integer
index = Val(e.CommandArgument)
Dim sr As GridViewRow = GridView1.SelectedRow
If e.CommandName = "disp" Then
Dim l As String
l = CType(sr.FindControl("fn"), Label).Text
End If
End Sub

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged

End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub
End Class

I need a quick solution for this
May 1 '07 #1
0 1069

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Punisher | last post: by
9 posts views Thread by Anders K. Jacobsen [DK] | last post: by
5 posts views Thread by Vigneshwar Pilli via DotNetMonster.com | last post: by
1 post views Thread by Guadala Harry | last post: by
1 post views Thread by KasperBirch | last post: by
reply views Thread by anandv81 | last post: by
reply views Thread by Mike Collins | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.