Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Gridview update code

Posted on 2008-10-30
4
Medium Priority
?
715 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 2000 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

Docker-Compose to Simplify Multi-Container Builds

Our veteran DevOps Author takes you through how to build a multi-container environment, managed with a single utility in order to simplify your deployments.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

721 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