Solved

Gridview update code

Posted on 2008-10-30
4
705 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
[X]
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
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

632 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