Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datagrid update problem

Status
Not open for further replies.

Zarcom

Programmer
May 7, 2002
1,275
CA
Hey guys n gals

Got a bit of a situation here. I am reading an xml file into a dataset and throwing it into a datagrid for view/editing. Everything seems to work just fine except when I go to update a record. The edit button puts the grid into it's edit mode. I change some of the data and press update. Now I am successfully able to take the data in the textboxes and update the dataset with it (heres the problem) But the textboxes don't contain any of my updated data. If the text box originally had "Mark" in it and I changed it to "marc" the code still sees the value in the text box as "Mark". I've posted the section of the code below. I am sure I am just being dumb and missing something so hopefull one of you can point it out for me.

//loop thru the datagrid columns and update the datset
for (int i=2; i <= dsAds1.Ad.Columns.Count; i++)
{
//get the text box in the row
TextBox t = (e.Item.Cells.Controls[0]) as TextBox;
//get the column as a boundcolumn type
BoundColumn col = dgrdAds.Columns as BoundColumn;
//if the column and the textbox is not null update the text
//TODO Why are the textbox's coming back with old data?
if (col != null && t != null)
{
//if t holds a blank string insert dbnull
if (t.Text ==&quot;&quot;)
dsAds1.Ad[e.Item.DataSetIndex][col.DataField] = DBNull.Value;
else
dsAds1.Ad[e.Item.DataSetIndex][col.DataField] = t.Text;
}


That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Sorry to waste all of your time. I have once again fell victim to page load misery. Problem was that I was binding the datagrid everytime so that when I hit the update button the grid was bound with the old data.

REMEMBER FOLKS!!
Always put your databind's inside of a if (!Page.IsPostBack) statment!

That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top