473,398 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Help with FindControl method

Joe
Hi,

Tried using the FindControl() but no luck in finidng this damn textbox
having id txtFirstName. Can someone help me with this method?

This is what I have been doing but it doesn't work,

Dim txtFName As TextBox

txtFName = CType(myDataGrid.FindControl("txtFirstName"), TextBox)
If Not (txtFName Is Nothing) Then
Label2.Text = txtFName.Text
Else
Label2.Text = "Control Not Found"
End If

Thank you for your help.

Joe

Here is my code:

<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<!-- #include file=dsn.aspx -->

<script language="VB" runat="server" >

Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
' Save the referrer Url
ViewState("ReferrerUrl") = Request.UrlReferrer.ToString()
BindData()
End If
End Sub

Sub BindData()
dim strsql as string
'check for an id
If Request.QueryString.Item("id") Is Nothing Then
response.redirect("Resultslist.aspx")
Else
strsql="select * from [Results] where [ID]=" &
request.querystring("id")
End If
'Create a connection string
Dim connString as String
connString = getdsn()

'Open a connection
Dim objConnection as OleDbConnection
objConnection = New OleDbConnection(connString)
objConnection.Open()

'Create a command object
Dim objCommand as OleDbCommand
objCommand = New OleDbCommand(strSQL, objConnection)
'Get a datareader
Dim objDataReader as OleDbDataReader
objDataReader =
objCommand.ExecuteReader(CommandBehavior.CloseConn ection)
'Do the DataBinding
myDataGrid.DataSource = objDataReader
myDataGrid.DataBind()

'Close the datareader/db connection
objDataReader.Close()
End Sub

Sub saveRec(Sender As Object, e As System.EventArgs)
dim strSQL as string
'check for an id
If Request.QueryString.Item("id") Is Nothing Then
response.redirect("Resultslist.aspx")
Else
strSQL="Update Results set first_name=@fn, last_name=@ln,
city=@ct where ID=" & request.querystring("id")
End If
'Create a connection string
Dim connString as String
connString = getdsn()

'Open a connection
Dim objConnection as OleDbConnection
objConnection = New OleDbConnection(connString)
objConnection.Open()

'Create a command object
Dim objCommand as OleDbCommand
objCommand = New OleDbCommand(strSQL, objConnection)

objCommand.Parameters.Add("@fn", OleDbType.VarChar, 255)
objCommand.Parameters.Add("@ln", OleDbType.VarChar, 255)
objCommand.Parameters.Add("@ct", OleDbType.VarChar, 255)

objCommand.Parameters("@fn").Value = txtFirstName.Text
objCommand.Parameters("@ln").Value = txtLastName.Text
objCommand.Parameters("@ct").Value = txtCity.Text

Try
Dim txtFName As TextBox

txtFName = CType(myDataGrid.FindControl("txtFirstName"), TextBox)
If Not (txtFName Is Nothing) Then
Label2.Text = txtFName.Text Else
Label2.Text = txtFName.Text '"Control Not Found"
End If

Catch Ex as Exception
Response.Write("<p><strong>An Error Occurred:</strong> " & Ex.ToString()
& "</p>" & vbCrLf)
Finally
objConnection.Close()

End Try

End Sub

Sub cancel(Sender As Object, e As EventArgs)
Response.Redirect(ViewState("ReferrerUrl").ToStrin g())
End Sub

</script>
<body>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:datagrid id="myDataGrid"
runat="server"
AutoGenerateColumns="False"
width="80%">
<ItemStyle Font-Size="X-Small"></ItemStyle>
<HeaderStyle Font-Size="X-Small" Font-Bold="True" ForeColor="White"
BackColor=""></HeaderStyle>

<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<b>Results detail</b>
</HeaderTemplate>
<ItemTemplate>
<table border="0" Cellpadding="4" Cellspacing="0" Width="80%"
style="FONT-SIZE: 11px; FONT-FAMILY: Verdana, Arial, sans-serif">
<tr><td valign="top" unselectable="on">first_name</td>
<td><asp:TextBox id="txtFirstName" runat="server" Width="109px" Text='<%#
Container.DataItem("first_name")%>' /></td>
</tr>
<tr><td valign="top">last_name</td><td><asp:TextBox id="txtLastName"
runat="server" Width="109px" Text='<%# Container.DataItem("last_name")%>'
/></td></tr>
<tr><td valign="top">city</td><td><asp:TextBox id="txtCity" runat="server"
Width="109px" Text='<%# Container.DataItem("city")%>' /></td></tr>
</table>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
<br />
<asp:Button ID="updateBtn" Runat="server" Text="Save Changes"
onclick="saveRec" />
<asp:Button ID="cancelBtn" Runat="server" Text="Cancel"
onclick="cancel" />
<asp:Label TEXT="" ID="Label2" Runat="Server" />

</form>
</center>
</body>
</html>


Nov 19 '05 #1
10 1698
"Joe" <Jo*@discussions.microsoft.com> wrote in message
news:6E**********************************@microsof t.com...
Hi,

Tried using the FindControl() but no luck in finidng this damn textbox
having id txtFirstName. Can someone help me with this method?

This is what I have been doing but it doesn't work,

Dim txtFName As TextBox

txtFName = CType(myDataGrid.FindControl("txtFirstName"),
TextBox)
If Not (txtFName Is Nothing) Then
Label2.Text = txtFName.Text
Else
Label2.Text = "Control Not Found"
End If


Don't you have more than one txtFirstName in the datagrid? One per row?

Also, in which event are you trying to do this?

John Saunders
Nov 19 '05 #2
Joe
I have only one txtFirstName control and I am trying to get reference to this
control and it's text value in saveRec sub.

Joe

"John Saunders" wrote:
"Joe" <Jo*@discussions.microsoft.com> wrote in message
news:6E**********************************@microsof t.com...
Hi,

Tried using the FindControl() but no luck in finidng this damn textbox
having id txtFirstName. Can someone help me with this method?

This is what I have been doing but it doesn't work,

Dim txtFName As TextBox

txtFName = CType(myDataGrid.FindControl("txtFirstName"),
TextBox)
If Not (txtFName Is Nothing) Then
Label2.Text = txtFName.Text
Else
Label2.Text = "Control Not Found"
End If


Don't you have more than one txtFirstName in the datagrid? One per row?

Also, in which event are you trying to do this?

John Saunders

Nov 19 '05 #3
I have an article with explanation and code on finding controls inside
of a grid:

http://odetocode.com/Articles/116.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Tue, 21 Dec 2004 11:07:03 -0800, Joe
<Jo*@discussions.microsoft.com> wrote:
Hi,

Tried using the FindControl() but no luck in finidng this damn textbox
having id txtFirstName. Can someone help me with this method?

This is what I have been doing but it doesn't work,

Dim txtFName As TextBox

txtFName = CType(myDataGrid.FindControl("txtFirstName"), TextBox)
If Not (txtFName Is Nothing) Then
Label2.Text = txtFName.Text
Else
Label2.Text = "Control Not Found"
End If

Thank you for your help.

Joe

Here is my code:

<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<!-- #include file=dsn.aspx -->

<script language="VB" runat="server" >

Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
' Save the referrer Url
ViewState("ReferrerUrl") = Request.UrlReferrer.ToString()
BindData()
End If
End Sub

Sub BindData()
dim strsql as string
'check for an id
If Request.QueryString.Item("id") Is Nothing Then
response.redirect("Resultslist.aspx")
Else
strsql="select * from [Results] where [ID]=" &
request.querystring("id")
End If
'Create a connection string
Dim connString as String
connString = getdsn()

'Open a connection
Dim objConnection as OleDbConnection
objConnection = New OleDbConnection(connString)
objConnection.Open()

'Create a command object
Dim objCommand as OleDbCommand
objCommand = New OleDbCommand(strSQL, objConnection)
'Get a datareader
Dim objDataReader as OleDbDataReader
objDataReader =
objCommand.ExecuteReader(CommandBehavior.CloseCon nection)
'Do the DataBinding
myDataGrid.DataSource = objDataReader
myDataGrid.DataBind()

'Close the datareader/db connection
objDataReader.Close()
End Sub

Sub saveRec(Sender As Object, e As System.EventArgs)
dim strSQL as string
'check for an id
If Request.QueryString.Item("id") Is Nothing Then
response.redirect("Resultslist.aspx")
Else
strSQL="Update Results set first_name=@fn, last_name=@ln,
city=@ct where ID=" & request.querystring("id")
End If
'Create a connection string
Dim connString as String
connString = getdsn()

'Open a connection
Dim objConnection as OleDbConnection
objConnection = New OleDbConnection(connString)
objConnection.Open()

'Create a command object
Dim objCommand as OleDbCommand
objCommand = New OleDbCommand(strSQL, objConnection)

objCommand.Parameters.Add("@fn", OleDbType.VarChar, 255)
objCommand.Parameters.Add("@ln", OleDbType.VarChar, 255)
objCommand.Parameters.Add("@ct", OleDbType.VarChar, 255)

objCommand.Parameters("@fn").Value = txtFirstName.Text
objCommand.Parameters("@ln").Value = txtLastName.Text
objCommand.Parameters("@ct").Value = txtCity.Text

Try
Dim txtFName As TextBox

txtFName = CType(myDataGrid.FindControl("txtFirstName"), TextBox)
If Not (txtFName Is Nothing) Then
Label2.Text = txtFName.Text Else
Label2.Text = txtFName.Text '"Control Not Found"
End If

Catch Ex as Exception
Response.Write("<p><strong>An Error Occurred:</strong> " & Ex.ToString()
& "</p>" & vbCrLf)
Finally
objConnection.Close()

End Try

End Sub

Sub cancel(Sender As Object, e As EventArgs)
Response.Redirect(ViewState("ReferrerUrl").ToStrin g())
End Sub

</script>
<body>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:datagrid id="myDataGrid"
runat="server"
AutoGenerateColumns="False"
width="80%">
<ItemStyle Font-Size="X-Small"></ItemStyle>
<HeaderStyle Font-Size="X-Small" Font-Bold="True" ForeColor="White"
BackColor=""></HeaderStyle>

<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<b>Results detail</b>
</HeaderTemplate>
<ItemTemplate>
<table border="0" Cellpadding="4" Cellspacing="0" Width="80%"
style="FONT-SIZE: 11px; FONT-FAMILY: Verdana, Arial, sans-serif">
<tr><td valign="top" unselectable="on">first_name</td>
<td><asp:TextBox id="txtFirstName" runat="server" Width="109px" Text='<%#
Container.DataItem("first_name")%>' /></td>
</tr>
<tr><td valign="top">last_name</td><td><asp:TextBox id="txtLastName"
runat="server" Width="109px" Text='<%# Container.DataItem("last_name")%>'
/></td></tr>
<tr><td valign="top">city</td><td><asp:TextBox id="txtCity" runat="server"
Width="109px" Text='<%# Container.DataItem("city")%>' /></td></tr>
</table>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
<br />
<asp:Button ID="updateBtn" Runat="server" Text="Save Changes"
onclick="saveRec" />
<asp:Button ID="cancelBtn" Runat="server" Text="Cancel"
onclick="cancel" />
<asp:Label TEXT="" ID="Label2" Runat="Server" />

</form>
</center>
</body>
</html>


Nov 19 '05 #4
Joe
Before posting this message, I read your article. But don't know where I am
making a mistake. Since I am a beginner, I am not able to spot the problem.

Joe

"Scott Allen" wrote:
I have an article with explanation and code on finding controls inside
of a grid:

http://odetocode.com/Articles/116.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Tue, 21 Dec 2004 11:07:03 -0800, Joe
<Jo*@discussions.microsoft.com> wrote:
Hi,

Tried using the FindControl() but no luck in finidng this damn textbox
having id txtFirstName. Can someone help me with this method?

This is what I have been doing but it doesn't work,

Dim txtFName As TextBox

txtFName = CType(myDataGrid.FindControl("txtFirstName"), TextBox)
If Not (txtFName Is Nothing) Then
Label2.Text = txtFName.Text
Else
Label2.Text = "Control Not Found"
End If

Thank you for your help.

Joe

Here is my code:

<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<!-- #include file=dsn.aspx -->

<script language="VB" runat="server" >

Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
' Save the referrer Url
ViewState("ReferrerUrl") = Request.UrlReferrer.ToString()
BindData()
End If
End Sub

Sub BindData()
dim strsql as string
'check for an id
If Request.QueryString.Item("id") Is Nothing Then
response.redirect("Resultslist.aspx")
Else
strsql="select * from [Results] where [ID]=" &
request.querystring("id")
End If
'Create a connection string
Dim connString as String
connString = getdsn()

'Open a connection
Dim objConnection as OleDbConnection
objConnection = New OleDbConnection(connString)
objConnection.Open()

'Create a command object
Dim objCommand as OleDbCommand
objCommand = New OleDbCommand(strSQL, objConnection)
'Get a datareader
Dim objDataReader as OleDbDataReader
objDataReader =
objCommand.ExecuteReader(CommandBehavior.CloseCon nection)
'Do the DataBinding
myDataGrid.DataSource = objDataReader
myDataGrid.DataBind()

'Close the datareader/db connection
objDataReader.Close()
End Sub

Sub saveRec(Sender As Object, e As System.EventArgs)
dim strSQL as string
'check for an id
If Request.QueryString.Item("id") Is Nothing Then
response.redirect("Resultslist.aspx")
Else
strSQL="Update Results set first_name=@fn, last_name=@ln,
city=@ct where ID=" & request.querystring("id")
End If
'Create a connection string
Dim connString as String
connString = getdsn()

'Open a connection
Dim objConnection as OleDbConnection
objConnection = New OleDbConnection(connString)
objConnection.Open()

'Create a command object
Dim objCommand as OleDbCommand
objCommand = New OleDbCommand(strSQL, objConnection)

objCommand.Parameters.Add("@fn", OleDbType.VarChar, 255)
objCommand.Parameters.Add("@ln", OleDbType.VarChar, 255)
objCommand.Parameters.Add("@ct", OleDbType.VarChar, 255)

objCommand.Parameters("@fn").Value = txtFirstName.Text
objCommand.Parameters("@ln").Value = txtLastName.Text
objCommand.Parameters("@ct").Value = txtCity.Text

Try
Dim txtFName As TextBox

txtFName = CType(myDataGrid.FindControl("txtFirstName"), TextBox)
If Not (txtFName Is Nothing) Then
Label2.Text = txtFName.Text Else
Label2.Text = txtFName.Text '"Control Not Found"
End If

Catch Ex as Exception
Response.Write("<p><strong>An Error Occurred:</strong> " & Ex.ToString()
& "</p>" & vbCrLf)
Finally
objConnection.Close()

End Try

End Sub

Sub cancel(Sender As Object, e As EventArgs)
Response.Redirect(ViewState("ReferrerUrl").ToStrin g())
End Sub

</script>
<body>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:datagrid id="myDataGrid"
runat="server"
AutoGenerateColumns="False"
width="80%">
<ItemStyle Font-Size="X-Small"></ItemStyle>
<HeaderStyle Font-Size="X-Small" Font-Bold="True" ForeColor="White"
BackColor=""></HeaderStyle>

<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<b>Results detail</b>
</HeaderTemplate>
<ItemTemplate>
<table border="0" Cellpadding="4" Cellspacing="0" Width="80%"
style="FONT-SIZE: 11px; FONT-FAMILY: Verdana, Arial, sans-serif">
<tr><td valign="top" unselectable="on">first_name</td>
<td><asp:TextBox id="txtFirstName" runat="server" Width="109px" Text='<%#
Container.DataItem("first_name")%>' /></td>
</tr>
<tr><td valign="top">last_name</td><td><asp:TextBox id="txtLastName"
runat="server" Width="109px" Text='<%# Container.DataItem("last_name")%>'
/></td></tr>
<tr><td valign="top">city</td><td><asp:TextBox id="txtCity" runat="server"
Width="109px" Text='<%# Container.DataItem("city")%>' /></td></tr>
</table>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
<br />
<asp:Button ID="updateBtn" Runat="server" Text="Save Changes"
onclick="saveRec" />
<asp:Button ID="cancelBtn" Runat="server" Text="Cancel"
onclick="cancel" />
<asp:Label TEXT="" ID="Label2" Runat="Server" />

</form>
</center>
</body>
</html>


Nov 19 '05 #5
"Joe" <Jo*@discussions.microsoft.com> wrote in message
news:36**********************************@microsof t.com...
I have only one txtFirstName control and I am trying to get reference to
this
control and it's text value in saveRec sub.


Joe, didn't you have a txtFirstName control inside of a template column? If
so, then that control is repeated once per row of the data grid.

If you run your page and then use View Source in IE, you'll see what I mean.
Search in the source for "txtFirstName", and you'll find several different
controls with that in their name.
Joe, you never said which event you're in. When are you trying to access
this control? That will help us show you how to do it properly, as some
events give you more help than others. Events like ItemCommand supply you
the DataGridItem (the row) in e.Item. You can then try

e.Item.FindControl("txtFirstName")

to get the txtFirstName in that row.

John Saunders
Nov 19 '05 #6
Joe
Hey John,

One one page I gave a datagrid and which shows say ten records from MS
Access DB. Then when I select a particular record to edi. Insted of editing
the record in the table, I go to another page on which only the selected
record display. This is the page I am having trouble with. In my first post I
posted my entire code if you want to have a look.

The buttons "Save Changes" and "Cancel" are outside the dataGrid. So when
"Save Changes" button is clicked, onClick even calls SavRec sub.

Here is the main part of my code. Hopefully this will help you spot the
mistake I am making,

<form id="Form1" method="post" runat="server">
<asp:datagrid id="myDataGrid"
runat="server"
ItemStyle-Font-Size="x-small"
HeaderStyle-Font-Bold="True"
HeaderStyle-Font-Size="x-small"
Cellpadding="4"
BorderWidth="1"
AutoGenerateColumns="False"
BorderStyle="Solid"
GridLines="Horizontal"
BorderColor=""
Font-Names="Verdana,Arial,sans-serif"
Font-Size="11px"
HorizontalAlign="center"
width="80%" >

<ItemStyle Font-Size="X-Small"></ItemStyle>
<HeaderStyle Font-Size="X-Small" Font-Bold="True" ForeColor="White"
BackColor=""></HeaderStyle>

<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<b>Results detail</b>
</HeaderTemplate>
<ItemTemplate>
<table border="0" Cellpadding="4" Cellspacing="0" Width="80%"
style="FONT-SIZE: 11px; FONT-FAMILY: Verdana, Arial, sans-serif">
<tr><td valign="top">ID</td><td><%# Container.DataItem("ID")%></td></tr>
<tr><td valign="top" unselectable="on">first_name</td>
<td><asp:TextBox id="txtFirstName" runat="server" Width="109px" Text='<%#
Container.DataItem("first_name")%>' /></td>
</tr>
<tr><td valign="top">last_name</td><td><asp:TextBox id="txtLastName"
runat="server" Width="109px" Text='<%# Container.DataItem("last_name")%>'
/></td></tr>
<tr><td valign="top">company</td><td><asp:TextBox id="txtCompany"
runat="server" Width="109px" Text='<%# Container.DataItem("company")%>'
/></td></tr>
<tr><td valign="top">street_address</td><td><asp:TextBox
id="txtStreetAddres" runat="server" Width="109px" Text='<%#
Container.DataItem("street_address")%>' /></td></tr>
<tr><td valign="top">address2</td><td><asp:TextBox id="txtAddres2"
runat="server" Width="109px" Text='<%# Container.DataItem("address2")%>'
/></td></tr>
<tr><td valign="top">city</td><td><asp:TextBox id="txtCity" runat="server"
Width="109px" Text='<%# Container.DataItem("city")%>' /></td></tr>
<tr><td valign="top">state</td><td><asp:TextBox id="txtState" runat="server"
Width="109px" Text='<%# Container.DataItem("state")%>' /></td></tr>
<tr><td valign="top">country</td><td><asp:TextBox id="txtCountry"
runat="server" Width="109px" Text='<%# Container.DataItem("country")%>'
/></td></tr>
<tr><td valign="top">postal</td><td><asp:TextBox id="txtPostal"
runat="server" Width="109px" Text='<%# Container.DataItem("postal")%>'
/></td></tr>
<tr><td valign="top">phone</td><td><asp:TextBox id="txtPhone" runat="server"
Width="109px" Text='<%# Container.DataItem("phone")%>' /></td></tr>
<tr><td valign="top">mobile</td><td><asp:TextBox id="txtMobile"
runat="server" Width="109px" Text='<%# Container.DataItem("mobile")%>'
/></td></tr>
<tr><td valign="top">email</td><td><asp:TextBox id="txtEmail" runat="server"
Width="109px" Text='<%# Container.DataItem("email")%>' /></td></tr>
<tr><td valign="top">password</td><td><asp:TextBox id="txtPassword"
runat="server" Width="109px" Text='<%# Container.DataItem("password")%>'
/></td></tr>
<tr><td valign="top">AddDate</td><td><asp:TextBox id="txtAddDate"
runat="server" Width="109px" Text='<%# Container.DataItem("AddDate")%>'
/></td></tr>
<tr><td valign="top">investor</td><td><asp:TextBox id="txtInvestor"
runat="server" Width="109px" Text='<%# Container.DataItem("investor")%>'
/></td></tr>
<tr><td valign="top">ViewDate</td><td><%#
Container.DataItem("ViewDate")%></td></tr>
<tr><td valign="top">RemoteIP</td><td><%#
Container.DataItem("RemoteIP")%></td></tr>
<tr><td valign="top">Cookie</td><td><%#
Container.DataItem("Cookie")%></td></tr>
</table>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
<br />
<asp:Button ID="updateBtn" Runat="server" Text="Save Changes"
onclick="saveRec" />
<asp:Button ID="cancelBtn" Runat="server" Text="Cancel"
onclick="cancel" />
<asp:Label TEXT="" ID="SPS" Runat="Server" />--<asp:Label TEXT=""
ID="pi" Runat="Server" />--<asp:Label TEXT="" ID="here" Runat="Server"
/>--<asp:Label TEXT="" ID="Label2" Runat="Server" />

</form>

Thanks John,

Joe

"John Saunders" wrote:
"Joe" <Jo*@discussions.microsoft.com> wrote in message
news:36**********************************@microsof t.com...
I have only one txtFirstName control and I am trying to get reference to
this
control and it's text value in saveRec sub.


Joe, didn't you have a txtFirstName control inside of a template column? If
so, then that control is repeated once per row of the data grid.

If you run your page and then use View Source in IE, you'll see what I mean.
Search in the source for "txtFirstName", and you'll find several different
controls with that in their name.
Joe, you never said which event you're in. When are you trying to access
this control? That will help us show you how to do it properly, as some
events give you more help than others. Events like ItemCommand supply you
the DataGridItem (the row) in e.Item. You can then try

e.Item.FindControl("txtFirstName")

to get the txtFirstName in that row.

John Saunders

Nov 19 '05 #7
"Joe" <Jo*@discussions.microsoft.com> wrote in message
news:09**********************************@microsof t.com...
Hey John,

One one page I gave a datagrid and which shows say ten records from MS
Access DB. Then when I select a particular record to edi. Insted of
editing
the record in the table, I go to another page on which only the selected
record display. This is the page I am having trouble with. In my first
post I
posted my entire code if you want to have a look.

The buttons "Save Changes" and "Cancel" are outside the dataGrid. So when
"Save Changes" button is clicked, onClick even calls SavRec sub.

Here is the main part of my code. Hopefully this will help you spot the
mistake I am making,

<form id="Form1" method="post" runat="server">
<asp:datagrid id="myDataGrid"
runat="server"
ItemStyle-Font-Size="x-small"
HeaderStyle-Font-Bold="True"
HeaderStyle-Font-Size="x-small"
Cellpadding="4"
BorderWidth="1"
AutoGenerateColumns="False"
BorderStyle="Solid"
GridLines="Horizontal"
BorderColor=""
Font-Names="Verdana,Arial,sans-serif"
Font-Size="11px"
HorizontalAlign="center"
width="80%" >


Is this DataGrid on the first page or the second?

In either case, it's still a DataGrid. Even if it only displays a single
row, it is a DataGrid.

You should try myDataGrid.Items(0).FindControl("txtFirstName").

John Saunders
Nov 19 '05 #8
Joe
Yes John. It worked. Can you explain why did you use Items(0)? Is it because
there is only one datagrid on the page?
Thanks again. I spent days on finding the problem and you solved it. You
are great.

Joe

"John Saunders" wrote:
"Joe" <Jo*@discussions.microsoft.com> wrote in message
news:09**********************************@microsof t.com...
Hey John,

One one page I gave a datagrid and which shows say ten records from MS
Access DB. Then when I select a particular record to edi. Insted of
editing
the record in the table, I go to another page on which only the selected
record display. This is the page I am having trouble with. In my first
post I
posted my entire code if you want to have a look.

The buttons "Save Changes" and "Cancel" are outside the dataGrid. So when
"Save Changes" button is clicked, onClick even calls SavRec sub.

Here is the main part of my code. Hopefully this will help you spot the
mistake I am making,

<form id="Form1" method="post" runat="server">
<asp:datagrid id="myDataGrid"
runat="server"
ItemStyle-Font-Size="x-small"
HeaderStyle-Font-Bold="True"
HeaderStyle-Font-Size="x-small"
Cellpadding="4"
BorderWidth="1"
AutoGenerateColumns="False"
BorderStyle="Solid"
GridLines="Horizontal"
BorderColor=""
Font-Names="Verdana,Arial,sans-serif"
Font-Size="11px"
HorizontalAlign="center"
width="80%" >


Is this DataGrid on the first page or the second?

In either case, it's still a DataGrid. Even if it only displays a single
row, it is a DataGrid.

You should try myDataGrid.Items(0).FindControl("txtFirstName").

John Saunders

Nov 19 '05 #9
"Joe" <Jo*@discussions.microsoft.com> wrote in message
news:A8**********************************@microsof t.com...
Yes John. It worked. Can you explain why did you use Items(0)? Is it
because
there is only one datagrid on the page?
Thanks again. I spent days on finding the problem and you solved it. You
are great.


It's not because there's only one DataGrid, it's because you told me that
there was only one item. At least you implied this.

You said that you have one page with a DataGrid, and that this grid displays
multiple rows. You said that when one of the rows was clicked, a second page
is displayed which only shows one row.

This second page contains the DataGrid you showed us. Because it's only
displaying a single row, I figured it would only have one Item - (0).

John Saunders
Nov 19 '05 #10
Joe
Thanks for explaining John.

Joe
"John Saunders" wrote:
"Joe" <Jo*@discussions.microsoft.com> wrote in message
news:A8**********************************@microsof t.com...
Yes John. It worked. Can you explain why did you use Items(0)? Is it
because
there is only one datagrid on the page?
Thanks again. I spent days on finding the problem and you solved it. You
are great.


It's not because there's only one DataGrid, it's because you told me that
there was only one item. At least you implied this.

You said that you have one page with a DataGrid, and that this grid displays
multiple rows. You said that when one of the rows was clicked, a second page
is displayed which only shows one row.

This second page contains the DataGrid you showed us. Because it's only
displaying a single row, I figured it would only have one Item - (0).

John Saunders

Nov 19 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: daniel.w.gelder | last post by:
Hey again. I'm still working on my functor class, and now it works with method functions too; you pass it the method function, as well as the object you want to be 'this' when the method is...
3
by: clintonG | last post by:
Briefly stated, my problem is accessing and 'setting' properties of a label control declared in the template of another control noting that the other control is an instance of the beta 2...
1
by: Gordon Keeler | last post by:
Hi all. I'm trying to develop an automated method of converting Access (97 or 2000) databases to SAS using DBMSCopy. I've discovered that there is not a rigid standard set to control the naming...
0
by: Gerrit Horeis | last post by:
Hi @all! I've got some problems with filling an arraylist with some Controls(Labels). When I have filled the arraylist I iterate through it then but cannot find the containing controls via the...
0
by: ani | last post by:
I have a datalist control in my aspx page(this is paginated and everytime submits to itself). I am calling a function within my datalist that returns a html control (radio button ) in the form of...
2
by: Karen | last post by:
Hi, We have a datagrid with a templated column. This column contains a textbox. Up until yestday this code (below) worked fine. str_note =...
1
by: Chris Calzaretta | last post by:
Hello, I need help with method descriptions for example when i say public var as new object.class and i go var.classmethod
1
by: Dan | last post by:
Hi, I created a custom control (ParentCustomControl) which is using a custom template (implementing ITemplate interface), in the instantiateIn method of this template I create all the controls I...
0
by: nagar | last post by:
On some PCs I have my application completely crash (with the standard Windows message) when I make a call to the Help.ShowHelp method to display the help guide Here's the call I make. Form...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.