Accessing cell value On update of Radgrid

13 posts, 1 answers
  1. Siva
    Siva avatar
    35 posts
    Member since:
    Mar 2013

    Posted 19 Mar 2013 Link to this post

    How to fetch a bound column cell value which is set to read only. on Update Command..?
    Please help me with a code..
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 19 Mar 2013 Link to this post

    Hi,

    Since  ReadOnly column will not be rendered in edit mode, a suggestion is to set the ReadOnly Column as the DataKeyName of the gridtableview and access the value as shown below.
    aspx:
    <MasterTableView  DataKeyNames="Id" >

    C#:
    protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
    {
             GridEditableItem editItem = (GridEditableItem)e.Item;
                string value = editItem.GetDataKeyValue("Id").ToString();
    }

    Thanks
    Princy.      
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Siva
    Siva avatar
    35 posts
    Member since:
    Mar 2013

    Posted 19 Mar 2013 Link to this post

    Thanks princy.. This code works fine :)
  5. Tc Blaize
    Tc Blaize avatar
    3 posts
    Member since:
    Mar 2013

    Posted 20 Mar 2013 Link to this post

    Please how do i set value of just on cell in a radgrid each time a method is run.
    NB: i want to achieve this in server-side.  
  6. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 21 Mar 2013 Link to this post

    Hi,

    Try the following code to achieve your scenario.
    c#:
    public void change()
     {
            foreach (GridDataItem dataItem in RadGrid1.Items)
            {
               dataItem["Uniquename"].Text="text";
             }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
            change();
    }

    Thanks,
    Princy
  7. James
    James avatar
    4 posts
    Member since:
    Oct 2012

    Posted 14 Apr 2014 Link to this post

    I am unable to retrieve the value of a cell when handling the UpdateCommand.  I am not using automatic updates or column generation.  I have read the docs and researched the forums to no avail.  This is so basic I know I have to be doing something really stupid :)  I have tried several different things including using EditMode of EditForms and InPlace.  I either get empty strings returned or "&nbsp".  See things I have attempted below.  Any help appreciated.


    Dim gei As GridEditableItem = TryCast(e.Item, GridEditableItem)

    id = gei("Id").Text
    Debug.Print("id: " & id)

    txtBox = TryCast(gei("Id").Controls(0), TextBox)
    If txtBox IsNot Nothing Then
        Debug.Print("txtBox: " & txtBox.Text)
    End If

    txtBox2 = TryCast(gei.Controls(0).FindControl("Id"), TextBox)
    If txtBox2 IsNot Nothing Then
        Debug.Print("txtBox2: " & txtBox2.Text)
    End If

    tc = gei("id")
    If tc IsNot Nothing Then
        Debug.Print(tc.Text)
    Else
        Debug.Print("tc Is Nothing")
    End If

    gei.ExtractValues(di)
    Debug.Print("di: " & di("Id").ToString)
  8. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 16 Apr 2014 in reply to James Link to this post

    Hi James,

    Please make sure you have not set the visibility of the column to false. Try the following code snippet to access the text in UpdateCommand.

    ASPX:
    <telerik:GridBoundColumn UniqueName="Id" DataField="Id" HeaderText="Id">
    </telerik:GridBoundColumn>

    VB:
    Protected Sub RadGrid1_UpdateCommand(sender As Object, e As GridCommandEventArgs)
        Dim edit As GridEditableItem = DirectCast(e.Item, GridEditableItem)
        Dim txtId As TextBox = DirectCast(edit("Id").Controls(0), TextBox)
        Dim idValue As String = txt.Text
    End Sub

    If this doesn't help, please provide your aspx page as well.

    Thanks,
    Princy
  9. James
    James avatar
    4 posts
    Member since:
    Oct 2012

    Posted 16 Apr 2014 in reply to Princy Link to this post

    Hi Princy

        Thanks very much for your quick reply.  I have verified that the column ("Id") is visible.  I also tested with your code snippet but continue to get an empty string when I check for the cell value.  I have include the code you requested:


    Protected Sub RadGrid1_UpdateCommand(sender As Object, e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.UpdateCommand

        Dim edit As GridEditableItem = DirectCast(e.Item, GridEditableItem)
        Dim txtId As TextBox = DirectCast(edit("Id").Controls(0), TextBox)
        Dim idValue As String = txtId.Text

    End Sub


    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False">
    <MasterTableView DataKeyNames="PriKey" EditMode="InPlace">
    <RowIndicatorColumn Visible="False">
    </RowIndicatorColumn>
    <ExpandCollapseColumn Created="True">
    </ExpandCollapseColumn>
    <Columns>
    <telerik:GridEditCommandColumn HeaderText="Edit">
    </telerik:GridEditCommandColumn>
    <telerik:GridBoundColumn DataField="PriKey"
    FilterControlAltText="Filter PriKey column" HeaderText="PriKey" ReadOnly="True"
    UniqueName="PriKey" Visible="False">
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn DataField="Id" FilterControlAltText="Filter Id column"
    HeaderText="Id" UniqueName="Id">
    </telerik:GridBoundColumn>
    </Columns>
    </MasterTableView>
    </telerik:RadGrid>

    Thanks again for your help.
  10. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 16 Apr 2014 in reply to James Link to this post

    Hi James,

    I'm not able to replicate the issue at my end. Below is a sample code snippet I tried which works as expected.

    ASPX:
    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" DataSourceID="SqlDataSource1">
        <MasterTableView DataKeyNames="OrderID" EditMode="InPlace">
            <Columns>
                <telerik:GridEditCommandColumn HeaderText="Edit">
                </telerik:GridEditCommandColumn>
                <telerik:GridBoundColumn DataField="OrderID" FilterControlAltText="Filter OrderID column" HeaderText="OrderID" ReadOnly="True" UniqueName="OrderID" Visible="False">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="EmployeeID" FilterControlAltText="Filter EmployeeID column" HeaderText="EmployeeID" UniqueName="EmployeeID">
                </telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="SELECT  * FROM [Orders]"></asp:SqlDataSource>

    VB:
    Protected Sub RadGrid1_UpdateCommand(sender As Object, e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.UpdateCommand
           Dim edit As GridEditableItem = DirectCast(e.Item, GridEditableItem)
           Dim txtId As TextBox = DirectCast(edit("EmployeeID").Controls(0), TextBox)
           Dim idValue As String = txtId.Text
           'OR
           Dim newValues As New Hashtable()
           e.Item.OwnerTableView.ExtractValuesFromItem(newValues, edit)
       End Sub

    Thanks,
    Princy
  11. James
    James avatar
    4 posts
    Member since:
    Oct 2012

    Posted 07 May 2014 in reply to Princy Link to this post

    Well, I tried your solution to no avail and I have experimented more hours than I care to admit with no success.  One thing I found that will allow me to extract the values is if I specified something other than GridBoundColumn.  If I use GridDateTimeColumn, GridNumericColumn or GridMaskedColumn I am able to extract the values but not if I use GridBoundColumn.  I don't seem to have a choice but move back to using GridView and writing alot of code.
  12. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 May 2014 in reply to James Link to this post

    Hi James,

    Unfortunately, I'm unable to replicate this issue at my end.

    Thanks,
    Princy
  13. James
    James avatar
    4 posts
    Member since:
    Oct 2012

    Posted 05 Jun 2014 in reply to Princy Link to this post

    Hi

        I developed a new form with a radgrid on it and was able to retrieve values from the cells.  Without making any other changes I placed the radgrid on a contentpage that uses a masterpage and it stopped working.  Are there any special tricks required when a master page is being used?
  14. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 05 Jun 2014 in reply to James Link to this post

    Hi James,

    The provided information is not adequate to identify the issue. Please provide your code snippet. In case if you are Ajaxifying your Grid please note that in a complex scenario like WebUserControls or Master/ContentPages, we strongly recommend you to place RadAjaxManager instance on the main/master page and add a proxy control to the user control/content page as described in the following help topic:
    RadAjax and MasterPage

    Thanks,
    Princy
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017