selecting radgrid row and displaying values in textboxes

9 posts, 1 answers
  1. yogesh
    yogesh avatar
    16 posts
    Member since:
    Feb 2011

    Posted 27 Feb 2011 Link to this post

    Hi,
        I am yogesh. I am new to asp.net with c# and working on telerik asp.netajax radgrid control. i want to select a row from radgrid and need to display values of row in textboxes which are in the same page.Could anyone help me out plz...
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 27 Feb 2011 Link to this post

    Hello Yogesh,

    Check out the following sample code snippet which shows how to achieve this. You can get the selected row and cell value in 'OnSelectedIndexChanged' event of RadGrid and then populate the TextBox(outside grid) with these values.

    ASPX:
    <telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"
        OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged">
        <MasterTableView>
            <Columns>
                <telerik:GridBoundColumn DataField="EmployeeID" UniqueName="EmployeeID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="FirstName" UniqueName="FirstName">
                </telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
        <ClientSettings Selecting-AllowRowSelect="true" EnablePostBackOnRowClick="true">
        </ClientSettings>
    </telerik:RadGrid>
    <br />
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

    C#:
    protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
       {
           GridDataItem selectedItem = (GridDataItem)RadGrid1.SelectedItems[0];//accessing selected row
           string value = selectedItem["FirstName"].Text;//getting cell value
           TextBox1.Text = value;
       }

    Note: You need to set 'EnablePostBackOnRowClick="true" to fire 'OnSelectedIndexChanged' od RadGrid.

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. yogesh
    yogesh avatar
    16 posts
    Member since:
    Feb 2011

    Posted 28 Feb 2011 Link to this post

    Thanks a lot princy.....its working for me with your code snippet....great work from you.




    Regards,
    Yogesh
  5. Ram
    Ram avatar
    97 posts
    Member since:
    Jun 2011

    Posted 30 Jun 2011 Link to this post

    Hi
    EnablePostBackOnRowClick="true"  property is not showing in radgrid.
    How can I set this property.
  6. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 30 Jun 2011 Link to this post

    Hello Ram,

    Try setting EnablePostBackOnRowClick in ClientSettings as shown below.

    aspx:
    <ClientSettings EnablePostBackOnRowClick="true" >
    </ClientSettings>

    Thanks,
    Princy.
  7. Chigicherla
    Chigicherla avatar
    2 posts
    Member since:
    Jul 2013

    Posted 23 Jul 2013 Link to this post

    protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
       {
           GridDataItem selectedItem = (GridDataItem)RadGrid1.SelectedItems[0];//accessing selected row
           string value = selectedItem["FirstName"].Text;//getting cell value
           TextBox1.Text = value;
       }

    The GridDataItem is not getting for me in Radgrid..

    Could you plz help me any thing else to be added in anywhere.....
  8. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 26 Jul 2013 Link to this post

    Hi ,

    I tried to replicate the issue but no avail,can you please try the following code snippet.If this doesn't help,please provide your full code,with your desired requirements.

    C#:
    protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
    {
    foreach (GridDataItem item in RadGrid1.SelectedItems)
      {
     foreach (GridColumn column in item.OwnerTableView.Columns)
      {
      Response.Write(String.Format("{0} : {1} <br />", column.UniqueName, item[column.UniqueName].Text));//Accessing Column Name,Column Value
      }
    }
    }

    Thanks,
    Shinu
  9. Jaakko
    Jaakko avatar
    4 posts
    Member since:
    Aug 2013

    Posted 27 Dec 2013 Link to this post

    GridDataItem seems to be a part of telerik.web.ui - had to figure that one out too.
  10. Muhammad
    Muhammad avatar
    3 posts
    Member since:
    Jan 2016

    Posted 15 Mar in reply to Princy Link to this post

    Thanks much Princy,

    I used your code and it works!

    There is something worth mentioning though, at least for novice users like myself, I needed to replace "GridDataItem" with "Telerik.Web.UI.GridDataItem".

    Also needed to reference this RadGrid1_SelectedIndexChanged in my RadGrid's Properties events, under "SelectedIndexChanged"

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