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

textbox value not returned in a datagrid

Hi all and thanks in advance for your help,

I have a problem with capturing the changed value of a text box in a
datagrid. The datagrid is populated based on a dataset and I am using
template columns to show some of the columns. Few of the columns have
textboxes to make them available for editing. I am trying to update the
dataset all at once using one update button. Here is my code... (for
simplicity I have only listed one of the columns)

================================================== ==========================
===
For the ASP.NET columns:

<asp:datagrid id="dgGED" runat="server" AutoGenerateColumns="False"
ItemStyle-BackColor="#E8E8E8"
HeaderStyle-BackColor="#D0D0D0" font-size="10pt" font-names="Arial"
gridlines="vertical"
Bordercolor="black">
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<B>EmpNumber</B>
</HeaderTemplate>
<ItemTemplate>
<center>
<asp:TextBox ID="txtEmpNum" Runat=server text='<%#
DataBinder.Eval(Container.DataItem, "EmpNumber") %>' size=5 style="border=0"

</asp:TextBox></center>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>

================================================== ==========================
===
The code behind C#:
//Iterate and apply changes.

string strEmpNumber = "";

foreach (DataGridItem item in dgGED.Items)

{

//Get value from grid.

strEmpNumber = (string)((TextBox) item.FindControl("txtEmpNum")).Text;

ds.Tables[0].Rows[item.ItemIndex]["EmpNumber"] = strEmpNumber;

}

================================================== ==========================
===

Just a few more notes: If I change the value of the textbox to some new
text, the strEmpNumber still shows the old value of the textbox before
editing (basically the original value that comes from the dataset). I don't
get any errors and everything seems to run just fine. So I don't know what
I am missing that the new change is not captured in the

strEmpNumber = (string)((TextBox) item.FindControl("txtEmpNum")).Text;

statement?

Any help and suggestions are truely appreciated,

Thanks a bunch,

Amadelle
Nov 18 '05 #1
1 1847
for those who are interested I found my problem.
I was making a mistake of regenrating the dataset in the PageLoad event
everytime - and bind it anew to the datagrid. So when the save button was
hit all the users input would basically disappear since the dataset/datagrid
would get regenerated from the datasource. So by adding a simple logic to
check post back or not, the problem was solved.

Thanks again,

Amadelle

"Amadelle" <am******@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi all and thanks in advance for your help,

I have a problem with capturing the changed value of a text box in a
datagrid. The datagrid is populated based on a dataset and I am using
template columns to show some of the columns. Few of the columns have
textboxes to make them available for editing. I am trying to update the
dataset all at once using one update button. Here is my code... (for
simplicity I have only listed one of the columns)

================================================== ========================== ===
For the ASP.NET columns:

<asp:datagrid id="dgGED" runat="server" AutoGenerateColumns="False"
ItemStyle-BackColor="#E8E8E8"
HeaderStyle-BackColor="#D0D0D0" font-size="10pt" font-names="Arial"
gridlines="vertical"
Bordercolor="black">
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<B>EmpNumber</B>
</HeaderTemplate>
<ItemTemplate>
<center>
<asp:TextBox ID="txtEmpNum" Runat=server text='<%#
DataBinder.Eval(Container.DataItem, "EmpNumber") %>' size=5 style="border=0"

</asp:TextBox></center>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>

================================================== ========================== ===
The code behind C#:
//Iterate and apply changes.

string strEmpNumber = "";

foreach (DataGridItem item in dgGED.Items)

{

//Get value from grid.

strEmpNumber = (string)((TextBox) item.FindControl("txtEmpNum")).Text;

ds.Tables[0].Rows[item.ItemIndex]["EmpNumber"] = strEmpNumber;

}

================================================== ========================== ===

Just a few more notes: If I change the value of the textbox to some new
text, the strEmpNumber still shows the old value of the textbox before
editing (basically the original value that comes from the dataset). I don't get any errors and everything seems to run just fine. So I don't know what I am missing that the new change is not captured in the

strEmpNumber = (string)((TextBox) item.FindControl("txtEmpNum")).Text;

statement?

Any help and suggestions are truely appreciated,

Thanks a bunch,

Amadelle

Nov 18 '05 #2

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

Similar topics

0
by: awightma | last post by:
Hi, I have a datagrid with a number of textboxes on it. I want one column of my table to be visible=false because it contains the id of the record from the table. For some reason when I set...
1
by: Amadelle | last post by:
Hi all and thanks in advance for your help, I have a problem with capturing the changed value of a text box in a datagrid. The datagrid is populated based on a dataset and I am using template...
3
by: Nic | last post by:
Hey, I have an ASP-application. In the ASPX I have an <asp:dropdownlist ..>. Now when I leave this control I want to initialisize some other fields. In window forms we uses the onleave event but...
7
by: I am Sam | last post by:
I have a DataGrid that is passing information to a stored procedure properly but the parameters aren't being casted properly. I was woundering if anyone can tell me how I should properly cast the...
0
by: Rogelio Moreno | last post by:
Denis, I recommend you to bind the textbox controls to columns of your table inside your dataset, then get the bindingmanagerbase for the table, then use the position property of the...
0
by: Tuomo | last post by:
Hi! I have a form (System.Web.UI.Page) that contains a DataGrid control and a DataTable that contains values for the data grid and that is data bound to the DataGrid. When I switch the grid to...
2
by: simon | last post by:
hello, new to vb.net, have a few questions about DataGrid. I have a dataGrid that is working pulling a dataset back from a stored proc and binding to the datagrid for display the datagrid's...
2
by: ismaelf | last post by:
i have a textbox in a template column in a datagrid, it displays the initial value of the row, but when i change it remains with the original value (it doesnt get the new value..) i fill the...
1
by: G | last post by:
Hello, Fairly new to .net (using c#). I am running an SQL query which always returns ONE ROW and no more. I would like to have the ID field of the returned row bound to a TextBox onSubmit. ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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...

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.