Solved

Gridview update code

Posted on 2008-10-30
4
696 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now