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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extract values to update gridview 1

Status
Not open for further replies.

BasicBoy

Programmer
Feb 22, 2008
156
ZA
I have this edit template in a gridview which shows when I go into edit mode :

<EditItemTemplate>
<asp:TextBox ID="txtEditMessage" runat="server" width="340px"
Text='<%# Eval("Message") %>'></asp:TextBox>
</EditItemTemplate>

I now need to update the row. How do I extract the value from this textbox to use it to update the record ?

I am using the RowUpdating event.

Thanks

 
Code:
var ctrl = e.Row.FindControl("txtEditMessage") as TextBox;
if(ctrl == null) return;
var value = ctrl.Text;
...
[code]

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Thanks - but C# is a bit greek to me. I prefer VB.NET if you do not mind.
 
jbenson - thanks for that.

The real problem I have is to extract the new (edited)values of these edited controls.

When I do this with this tip, I get the values before those controls were updated - or maybe after they have been posted back without being updated - I am not sure. As I understand it - as soon as I click the Update button the grid is posted back - and the edit controls are then again filled with the unupdated fields from the database.

I am presently extracting these values in the RowUpdating event, although I have also tried the RowEditing event (with the same negative result)

In which event or how can I extract the correct (current) edited data in these edit controls ?

Thanks
 
the problem isn't extracting the values. chances are you are always binding data to the gridview, even on postback, thus overwriting the new values.
a common scenario is to bind the data to the gridview on page load. however, you also need to check for postback.
Code:
protected void Page_Load(object sender, EventArgs e)
{
  if(IsPostback) return;

  bind data to grid view.
}

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Jason you get the honour - wish I could give you more stars.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top