This is a migrated thread and some comments may be shown as answers.

Radgrid update

4 Answers 110 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eva
Top achievements
Rank 1
Eva asked on 16 Aug 2011, 12:44 AM

I'm editing radgrid using template
here is my code

 

<

 

 

EditFormSettings EditFormType="Template">

 

 

 

<FormTemplate>

 

 

 

<table id="Table2" cellspacing="2" cellpadding="1" width="100%" border="0" rules="none" >

 

 

 

<tr class="EditFormHeader">

 

 

 

<td colspan="2" style="font-size: small"><b>Name</b></td>

 

 

 

<td><asp:TextBox runat="server" ID="Name" Width="250px" Text='<%# Bind("Name") %>' /></td>

 

 

 

 

</tr>

 

 

 

<tr class="EditFormHeader">

 

 

 

<td colspan="2" style="font-size: small">

 

 

 

<b>Title</b>

 

 

 

</td>

 

 

 

 

<td><asp:TextBox runat="server" ID="Title" Width="250px" Text='<%# Bind("Title") %>' /></td>

 

 

 

</tr>

I am updating from code behind


 

protected

 

 

void radgrid_UpdateCommand(object source, GridCommandEventArgs e)

 

{

 

 

GridEditableItem editedItem = e.Item as GridEditableItem;

 

 

 

TextBox txtName = (TextBox)editedItem.FindControl("Name");

 

 

 

string Name = txtName .Text;

 

 

 

TextBox txtTitle = (TextBox)editedItem.FindControl("Title");

 

 

 

string Title = txtTitle.Text;
}

But this update 'Name' and 'Title' returns the old values not the updated one.

Need help.

 

 

4 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 16 Aug 2011, 05:54 AM
Hello Eva,

please use Advanced Data Binding for binding the datasource to Radgrid.
or
Let me know by which way you bind datasource to Radgrid.

Thanks,
Jayesh Goyani
0
Eva
Top achievements
Rank 1
answered on 16 Aug 2011, 06:03 AM
Yes, i'm using the advanced data binding also editing using template form.

Could you please provide a code sample for editing in code behind , for template form type.

0
Princy
Top achievements
Rank 2
answered on 16 Aug 2011, 06:27 AM
Hello Eva,

I suppose you are calling databind() method before calling the update method. If so it wil replace the new values with the old DB value. Here is the sample code that I tried which worked as expected.

aspx:
<EditFormSettings EditFormType="Template" >
    <FormTemplate>
  <asp:TextBox runat="server" ID="Title" Width="250px" Text='<%# Bind("Name") %>'></asp:TextBox>
<asp:Button ID="Button2" runat="server" CommandName="Update" Text="Update" />
  </FormTemplate>
</EditFormSettings>

C#:
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
{
        GridEditableItem editItem = e.Item as GridEditableItem;
          TextBox title = (TextBox)editItem.FindControl("Title");
         string Title = title.Text;
}

Thanks,
Princy.
0
Rakesh Gupta
Top achievements
Rank 2
answered on 16 Aug 2011, 06:45 AM
Hello Eva,

As i can see that the NeedDataSource may be called after UpdateCommand. So it Refreshes the Grid and you are getting old value which are stored in Database.

In Your Code behind i can't see the code which updates the Database Values.

Still if you are not able to track the issue let me know.

--
Thanks & Regards,
Rakesh T. Gupta
Tags
Grid
Asked by
Eva
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Eva
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Rakesh Gupta
Top achievements
Rank 2
Share this question
or