Radgrid update

5 posts, 0 answers
  1. Eva
    Eva avatar
    50 posts
    Member since:
    Jun 2010

    Posted 15 Aug 2011 Link to this post

    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.

     

     

  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 16 Aug 2011 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Eva
    Eva avatar
    50 posts
    Member since:
    Jun 2010

    Posted 16 Aug 2011 Link to this post

    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.

  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 16 Aug 2011 Link to this post

    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.
  6. Rakesh Gupta
    Rakesh Gupta avatar
    12 posts
    Member since:
    Oct 2010

    Posted 16 Aug 2011 Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017