473,387 Members | 1,347 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,387 software developers and data experts.

how to edit a textbox field populated by data from a datalist?

Inside my .aspx file, I have a textbox populated with data from a dataset
like this:

<asp:TextBox text='<%# DataBinder.Eval(Container.DataItem, "Comment")%>'
id="CommentText" runat="server" TextMode="MultiLine"></asp:TextBox>
</ItemTemplate>
</asp:datalist>
<asp:button id="EditCommentButton" Text="Edit Comment"
Runat="server"></asp:button

In my .aspx.cs file, I have a method:

private void EditCommentButton_Click(object sender, System.EventArgs e)
{
string editedComment = CommentText.Text.ToString();
// then here do an UPDATE
SqlConnection dataConnection = new SqlConnection(CONNECTION_STRING);
SqlCommand dataCommand = new SqlCommand();
dataCommand.CommandText = "UPDATE table SET Comment = '" + editedComment +
"' ";
dataCommand.CommandText += "WHERE blah blah blah";

}

My codes is able to populate the textbox with all the comments in the html
page, but I cannot edit the text when firing on the "EditCommentButton_Click"
method.
I would get an error: "Object reference not set to an instance of an object".
Is this line incorrect? --> string editedComment =
CommentText.Text.ToString( )

I know the SQL Update works fine because if I do:
string editedComment = "HELLO WORLD";
then the textbox would be updated. So I guess something is wrong with
"CommentText.Text.ToString( )" and it is not casting to a string or something.
How should I change my codes so I can edit a populated textbox field?
Nov 19 '05 #1
2 5492
Hi,

You cannot refer the textbox control 'CommentText' in your code behind
while editing the datagrid row.

Try this code in EditCommentButton_Click event

System.Web.UI.WebControls.TextBox txtComment = new TextBox();
txtComment = (System.Web.UI.WebControls.TextBox)e.Item.FindCont rol("CommentText");
string editedComment = txtComment.Text;

Regards,
Ravi

donnet <do****@discussions.microsoft.com> wrote in message news:<9A**********************************@microso ft.com>...
Inside my .aspx file, I have a textbox populated with data from a dataset
like this:

<asp:TextBox text='<%# DataBinder.Eval(Container.DataItem, "Comment")%>'
id="CommentText" runat="server" TextMode="MultiLine"></asp:TextBox>
</ItemTemplate>
</asp:datalist>
<asp:button id="EditCommentButton" Text="Edit Comment"
Runat="server"></asp:button

In my .aspx.cs file, I have a method:

private void EditCommentButton_Click(object sender, System.EventArgs e)
{
string editedComment = CommentText.Text.ToString();
// then here do an UPDATE
SqlConnection dataConnection = new SqlConnection(CONNECTION_STRING);
SqlCommand dataCommand = new SqlCommand();
dataCommand.CommandText = "UPDATE table SET Comment = '" + editedComment +
"' ";
dataCommand.CommandText += "WHERE blah blah blah";

}

My codes is able to populate the textbox with all the comments in the html
page, but I cannot edit the text when firing on the "EditCommentButton_Click"
method.
I would get an error: "Object reference not set to an instance of an object".
Is this line incorrect? --> string editedComment =
CommentText.Text.ToString( )

I know the SQL Update works fine because if I do:
string editedComment = "HELLO WORLD";
then the textbox would be updated. So I guess something is wrong with
"CommentText.Text.ToString( )" and it is not casting to a string or something.
How should I change my codes so I can edit a populated textbox field?

Nov 19 '05 #2
Ravi,

when trying to compile, I get the following error "System.EventArgs does not
contain a definition for 'Item' "

(System.Web.UI.WebControls.TextBox)e.Item.FindCont rol("CommentText");

I don't know whether it's relevant in here, but you mentionned i cannot
refer a text box control when editing datagrid row, however i'm using a
datalist... doesn't a datalist allow you for more html freedom and is not as
restrictive as a datagrid.
"Ravi" wrote:
Hi,

You cannot refer the textbox control 'CommentText' in your code behind
while editing the datagrid row.

Try this code in EditCommentButton_Click event

System.Web.UI.WebControls.TextBox txtComment = new TextBox();
txtComment = (System.Web.UI.WebControls.TextBox)e.Item.FindCont rol("CommentText");
string editedComment = txtComment.Text;

Regards,
Ravi

donnet <do****@discussions.microsoft.com> wrote in message news:<9A**********************************@microso ft.com>...
Inside my .aspx file, I have a textbox populated with data from a dataset
like this:

<asp:TextBox text='<%# DataBinder.Eval(Container.DataItem, "Comment")%>'
id="CommentText" runat="server" TextMode="MultiLine"></asp:TextBox>
</ItemTemplate>
</asp:datalist>
<asp:button id="EditCommentButton" Text="Edit Comment"
Runat="server"></asp:button

In my .aspx.cs file, I have a method:

private void EditCommentButton_Click(object sender, System.EventArgs e)
{
string editedComment = CommentText.Text.ToString();
// then here do an UPDATE
SqlConnection dataConnection = new SqlConnection(CONNECTION_STRING);
SqlCommand dataCommand = new SqlCommand();
dataCommand.CommandText = "UPDATE table SET Comment = '" + editedComment +
"' ";
dataCommand.CommandText += "WHERE blah blah blah";

}

My codes is able to populate the textbox with all the comments in the html
page, but I cannot edit the text when firing on the "EditCommentButton_Click"
method.
I would get an error: "Object reference not set to an instance of an object".
Is this line incorrect? --> string editedComment =
CommentText.Text.ToString( )

I know the SQL Update works fine because if I do:
string editedComment = "HELLO WORLD";
then the textbox would be updated. So I guess something is wrong with
"CommentText.Text.ToString( )" and it is not casting to a string or something.
How should I change my codes so I can edit a populated textbox field?

Nov 19 '05 #3

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

Similar topics

4
by: Javier Gomez | last post by:
I have a query field which is a non editable field because is a function's result. Due to I need to edit the information, Can you please suggest me any solution for this problem?? (No matter...
3
by: Hartmut Schroth | last post by:
Hi, I need a solution for the following problem: In the item template of a datalist control I have already a button control with the commandname set to "select" to perform some specific...
0
by: Alex | last post by:
Interested in more .NET stuff visit www.dedicatedsolutions.co.uk The DataList is not as powerful as the DataGrid. It requires more work from you since it has no default data presentation format....
0
by: Alex | last post by:
Imports System Imports System.Data Imports System.Data.SqlClient Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Configuration Public Class Main : Inherits Page ...
4
by: tshad | last post by:
I have a DataList that I have set up to allow editing. The edit button does go to the subroutine defined by OnEditCommand. The problem is that it doesn't change the fields to editing fields. The...
2
by: Playmaker | last post by:
Hopefully someone else has come across this issue. What I have is a SQL Server 2000 back-end. I've created a simple webform which has both Gridview and DataList controls on it populated with a...
1
by: cyningeston | last post by:
OS: WinXP Pro, VB/ASP/ADO.NET I'm building a web-based supplier management application. For each supplier we are required by the FDA to track certain documents. I've managed to pull them from...
2
by: Blasting Cap | last post by:
I have a couple fields (one varchar 20, one varchar 500) for a PO Number & a comment field on a datagrid. Once they're entered, a user can edit them and make changes to them. However, when...
6
by: john | last post by:
I have the following textbox setup with Text & ToolTip Bindings as follows; I'm using Visual Studio 2008 VB: <asp:TextBox ID="txtDay1" runat="server" Text='<%# Eval("Day1") %>'...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.