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

Prefill Textbox with Data from Grid

1 Answer 80 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brett
Top achievements
Rank 1
Brett asked on 15 Jul 2014, 10:30 PM
When I click on an item I would like to fill my TextBox with numbers from a column from Grid2 after Grid1 is clicked. Right now if I click on an item in Grid1 it will then run a procedure that will fill Grid2 with data. Here is an example of the current functionality with picture attached. I click an item from Grid1 and it has 3 results, my textbox will still display as an empty textbox. Then I click another item in Grid1 and now my textbox will display the 3 results from the previously clicked item. How can I display the correct numbers in my textbox after an item is selected in Grid1. 

Here are some snippets of what I currently have:
protected void Grid_Product_List_Details_PreRender(object sender, EventArgs e)
    {
        RadGrid grid = (RadGrid)sender;
 
        if (grid.Items.Count > 0)
            {
                RadTextBox1.Text = "";
            }
 
        for (int i = 0; i < grid.Items.Count; i++)
            {
 
                RadTextBox1.Text += grid.Items[i].GetDataKeyValue("number").ToString() + "\n";
            }
        RadTextBox1.DataBind();
 
    }


or I can comment out the above and use this to achieve the same results which are not correct:
protected void Grid_Product_List_Header_SelectedIndexChanged(object sender, EventArgs e)
    {
        RadTextBox1.Text = "";
        for (int i = 0; i < Grid_Product_List_Details.Items.Count; i++)
        {
 
            RadTextBox1.Text += Grid_Product_List_Details.Items[i].GetDataKeyValue("number").ToString() + "\n";
        }    
    }

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 16 Jul 2014, 08:13 AM
Hi Brett,

If you are using RadAjaxManager to ajaxify your grid, make sure you have included the RadTextBox in the UpdatedControls. And set the RadTextBox text in the PreRender event of the first Grid. Take a look at the sample code snippet:

ASPX:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadGrid1">
            <UpdatedControls>
             <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
             <telerik:AjaxUpdatedControl ControlID="RadGrid2"></telerik:AjaxUpdatedControl>      
             <telerik:AjaxUpdatedControl ControlID="RadTextBox1"></telerik:AjaxUpdatedControl>
            </UpdatedControls>
        </telerik:AjaxSetting>
        <telerik:AjaxSetting AjaxControlID="RadGrid2">
            <UpdatedControls>
             <telerik:AjaxUpdatedControl ControlID="RadGrid2"></telerik:AjaxUpdatedControl>          
            </UpdatedControls>
        </telerik:AjaxSetting>      
    </AjaxSettings>
</telerik:RadAjaxManager>

C#:
void RadGrid1_PreRender(object sender, EventArgs e)
{
  RadTextBox1.Text = "";
  foreach (GridDataItem dataItem in RadGrid2.Items)
  {
    RadTextBox1.Text += dataItem.GetDataKeyValue("number").ToString() + "\n";
  }
  RadTextBox1.DataBind();
}

Thanks,
Princy
Tags
Grid
Asked by
Brett
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or