Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Gridview update code

Posted on 2008-10-30
4
700 Views
Last Modified: 2012-05-05
I am updating a gridview using c# code. I am trying to capture the new values from the gridveiw after I click edit... therefore I have been using the following code.

    protected void edit_record_updating(object sender, GridViewUpdateEventArgs e)
    {
       
        update_class update_records_method = new update_class();
        update_records_method.Record_ID = ((TextBox)user_records.Rows[e.RowIndex].Cells[2].Controls[0]).Text.ToString();
        update_records_method.Logon_Name = WindowsIdentity.GetCurrent().Name.ToString();
        update_records_method.Record_Class = ((TextBox)user_records.Rows[e.RowIndex].Cells[4].Controls[0]).Text.ToString();  
        update_records_method.Record_Name = ((TextBox)user_records.Rows[e.RowIndex].Cells[6].Controls[0]).Text.ToString();
}

The problem is that not text seems to be  being picked up when I entre it into the text boxes
0
Comment
Question by:Mr_Shaw
  • 2
  • 2
4 Comments
 
LVL 14

Expert Comment

by:Ramuncikas
ID: 22845773
Make sure your textboxes have IDs assigned and try to use this:
update_records_method.Record_ID = ((TextBox)user_records.Rows[e.RowIndex].FindControl("IdTextBox")).Text;

Open in new window

0
 

Author Comment

by:Mr_Shaw
ID: 22845959
How do I create ID's for the textboxes used in the Gridview...They seem to be created dynamicly.
0
 
LVL 14

Accepted Solution

by:
Ramuncikas earned 500 total points
ID: 22887942
Sorry for delay.

I thought you were using TemplateFields.

In this case your code is correct. The problem is elsewhere. I'd suspect that you bind old data to grid before Updating event takes place. A common error is data is bound to grid in Page_Load event ALWAYS but should be bound only on initial page load.

If you would give more code it might be helpful.

R
if (!this.IsPostBack)
{
  ... // bind grid here
}

Open in new window

0
 

Author Closing Comment

by:Mr_Shaw
ID: 31511688
thanks for the help all sorted now. The code which I used was

update_records_method.Record_ID = ((TextBox)user_records.Rows[e.RowIndex].Cells[2].Controls[0]).Text.ToString();

 
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question