[?]How to get value of GridDataBound in EditMode

3 posts, 0 answers
  1. Tan
    Tan avatar
    17 posts
    Member since:
    Feb 2012

    Posted 18 Mar 2012 Link to this post

    Hi all,
    I have a problem with my radGrid. My code below:
    ======ASPX code=====
    <telerik:RadGrid ID="rgData" runat="server" AutoGenerateColumns="false"
                               onupdatecommand="rgData_UpdateCommand1">
                <MasterTableView DataKeyNames="ID" >
                <PagerStyle Mode="NextPrevAndNumeric" />
                <Columns>
                          <telerik:GridBoundColumn  DataField="Name"
                                                                UniqueName="clName"
                                                                   HeaderText="Name" >
                          </telerik:GridBoundColumn>
                </Columns>
    </telerik:RadGrid>
    =====C# code========
    protected void rgData_UpdateCommand1(object sender, GridCommandEventArgs e)
            {
                GridEditableItem item = (GridEditableItem)e.Item;
                string value = (item["clName"].Controls[0] as TextBox).Text;
            }
    ===================
    When I debug, I only get value of column Name, not the value I set in edit mode.
    this is my Grid:  http://i1068.photobucket.com/albums/u450/bl4ir121/Error_RadGrid.jpg
    I try get Kevin value but I only get John value.
    Please help me, It's very important.
    Thank all.
  2. msigman
    msigman avatar
    141 posts
    Member since:
    Apr 2008

    Posted 18 Mar 2012 Link to this post

    Hi Tan,

    See if this gets you started:
    private void rgData_UpdateCommand1(object source, GridCommandEventArgs e)
    {
       GridEditableItem editedItem = e.Item as GridEditableItem;
       Hashtable newValues = new Hashtable();
       e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
       changedRows[0].BeginEdit();
       try
       {
           foreach (DictionaryEntry entry in newValues)
           {
               changedRows[0][(string)entry.Key] = entry.Value;
           }
           changedRows[0].EndEdit();
       }
       catch (Exception ex)
       {
           changedRows[0].CancelEdit();
           Label1.Text += "Unable to update. Reason: " + ex.Message;
           e.Canceled = true;
       }
    }


    If that is not what you want, you can try the ExtractValues() method as well:
    private void rgData_UpdateCommand1(object source, GridCommandEventArgs e)
    {
        GridEditableItem ei = ((GridEditableItem)(e.Item));
        Hashtable t1 = new Hashtable();
        ei.ExtractValues(t1);
    }
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tan
    Tan avatar
    17 posts
    Member since:
    Feb 2012

    Posted 18 Mar 2012 Link to this post

    Hello msigman,
    First, I thank you so much for ur reply. I already resolve my problem. I call ReBind() in the ItemCommand event without if else statement, so it call ItemCommand event every I click Update button, and ItemCommand event call ReBind(), and the value I set become the value binded in grid.
    thanks you again msigman.^^
Back to Top