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

Accessing controls of Newly created row of radgrid

1 Answer 43 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Aditi
Top achievements
Rank 1
Aditi asked on 08 Oct 2012, 08:34 PM
Hi,

I have a radgrid on page. which has few textbox conrols, comobox, button etc in grid.
We create row dynamically. Clicking on + sign from grid footer and then it creates a new row.
On new row, we have some input boxes for user to enter info. One os theinput is such that, it has textbox control and button besieds a text box. clicking on button opens a pop up window, user will enter some value in pop window text box, whixh will be passed back from pop up to radgrid textbox control. For existing row it can access the row and textbox control for that row, however for newly created row it throws exception.

Please suggest.

Thanks,
Aditi

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 09 Oct 2012, 05:22 AM
Hi,

Please check the following code snippet I tried to pass the pop up textbox value to the textbox in insert mode.

ASPX:
<telerik:RadWindowManager ID="RadWindowManager1" runat="server">
    <Windows>
        <telerik:RadWindow ID="RadWindow1" runat="server">
            <ContentTemplate>
                <asp:TextBox ID="textbox2" runat="server" AutoPostBack="true"
                    ontextchanged="textbox2_TextChanged"></asp:TextBox>
            </ContentTemplate>
        </telerik:RadWindow>
    </Windows>
</telerik:RadWindowManager>
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1"
        AutoGenerateColumns="false" AutoGenerateEditColumn="true"
        onitemcreated="RadGrid1_ItemCreated">
    <MasterTableView CommandItemDisplay="Top">
        <Columns>
            <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID"></telerik:GridBoundColumn>
            <telerik:GridTemplateColumn>
                <EditItemTemplate>
                    <asp:TextBox ID="Textbox1" runat="server"></asp:TextBox>
                    <asp:Button ID="Button1" runat="server" Text="Submit" />
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

C#:
void Button1_Click(object sender, EventArgs e)
{
    string scriptstring = "<script language='javascript'>function f(){var oWnd = radopen('', 'RadWindow1');}; Sys.Application.add_load(f) ;</script>";
    Page.ClientScript.RegisterStartupScript(this.GetType(), "radalert", scriptstring);
}
  
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
   if (e.Item is GridEditableItem && e.Item.IsInEditMode)
   {
       if (e.Item is GridEditFormInsertItem || e.Item is GridDataInsertItem)
       {
           GridEditFormInsertItem item = (GridEditFormInsertItem)e.Item;
           Button Button1 = (Button)item.FindControl("Button1");
           Button1.Click += new EventHandler(Button1_Click);
       }
   }
}
protected void textbox2_TextChanged(object sender, EventArgs e)
{
   GridEditFormInsertItem item = (GridEditFormInsertItem)RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem)[0];
   TextBox txt = (TextBox)item.FindControl("Textbox1");
   txt.Text = textbox2.Text;
}

Thanks,
Shinu.
Tags
Grid
Asked by
Aditi
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or