469,609 Members | 1,230 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

textbox in datagrid problem getting the changed value

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 16 '05 #1
1 15551
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****************@TK2MSFTNGP10.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 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by d.steininger | last post: by
2 posts views Thread by Mike | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.