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

Update Grid's control from Popup window

6 Answers 334 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mukesh
Top achievements
Rank 1
Mukesh asked on 17 Sep 2010, 05:57 AM
Hi,

I am using Radgrid with inline editing... and on clicking on a button inside edited row, I am opening a popup window.

The Popup window has a textbox and a submit button.

Now when I click on submit button from popup, i want to update the textbox value to parent page (inside radgrid edited row).


For more details please have a look on attached screenshot




Thanks
Mukesh

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Sep 2010, 09:39 AM
Hello,


Here is one suggestion to achieve this:

  • Access the button control in editform, also get the textbox value in ItemDataBound event.
  • Now attach the "onclick" to button by passing the textbox value.
  • In the client side event handler, open the window using any f the methods in documentation.
  • Pass the textbox value as url query string when creating url.
  • In the pageload event of RadWindow page, get the url parameter and populate the textbox.



-Shinu.
0
Mukesh
Top achievements
Rank 1
answered on 17 Sep 2010, 01:45 PM
Hi Shinu,

Thanks for your promt reply, but this can't solve my problem, because I don't have to refresh the parent page.
If i refresh the parent page the grid's edit mode will be disappear.


Thanks
Mukesh
0
Mukesh
Top achievements
Rank 1
answered on 18 Sep 2010, 06:32 AM
Hi Shinu,

I am using Grid's inline editing, and I am able to get textbox of grid for existing rows by following code:               

                var grid = $find("<%=grdRouting.ClientID %>"); 
                var MasterTable = grid.get_masterTableView(); 
                var textbox = MasterTable.get_dataItems()[index].findElement("txtUserValue");

But I am unable to get the textbox of newly added row. because its not the part of MasterTable.get_dataItems()

So, how can I access the textbox of newly added row.


Thanks
Mukesh
0
Accepted
Shinu
Top achievements
Rank 2
answered on 18 Sep 2010, 11:06 AM
Hello Mukesh,

You can try the following approach to achieve your requirement.

  • Open the Radwindow in OnClientClick event of Button(which is inside ItemTemplate of RadGrid).
  • In ItemCreated event save the ClientID of TextBox (which is inside ItemTemplate of RadGrid) in a HiddenField.
  • Then attach an 'onclick' event to the 'Submit' button(which is inside RadWindow) from code behind and pass the ClientID of the TextBox(inside RadWindow) to the event handler.
  • In that 'onclick' event handler access the TextBox inside ItemTemplate using the HiddenField.

ASPX:
<telerik:RadWindow ID="RadWindow2" runat="server">
    <ContentTemplate>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:Button ID="Button2" runat="server" Text="Submit" />
    </ContentTemplate>
</telerik:RadWindow>
 
<telerik:RadGrid . . . . . . .>
. . . . . . . .
<Columns>
    <telerik:GridTemplateColumn>
        <ItemTemplate>
            <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
        </ItemTemplate>
    </telerik:GridTemplateColumn>
    <telerik:GridTemplateColumn>
        <ItemTemplate>
            <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return openWindow();" />
        </ItemTemplate>
    </telerik:GridTemplateColumn>
</Columns>
. .  . . . . .
</telerik:RadGrid>
 
<asp:HiddenField ID="HiddenField1" runat="server" />

Java Script:
<script type="text/javascript">
   function openWindow() // to open RadWindow
     {
        var oWnd = $find("RadWindow2");
        oWnd.show();
        return false;
     }
  function OnClick(txtid)
    {
        var textbox1 = document.getElementById(txtid);
        var textbox2 = document.getElementById(document.getElementById('HiddenField1').value);
        textbox2.value = textbox1.value;
        return false;
     }
</script>

C#:
protected void Page_Load(object sender, EventArgs e)
   {
       RadWindow window = (RadWindow)this.FindControl("RadWindow2");
       Button btn = (Button)window.ContentContainer.FindControl("Button2");
       TextBox txt2 = (TextBox)window.ContentContainer.FindControl("TextBox2");
       btn.Attributes.Add("onclick", "return OnClick('" + txt2.ClientID + "');");
   }
 
 
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridDataInsertItem && e.Item.OwnerTableView.IsItemInserted)
       {
           GridDataInsertItem inserItem = (GridDataInsertItem)e.Item;
           TextBox txt = (TextBox)inserItem.FindControl("TextBox1");
           HiddenField1.Value = txt.ClientID;
       }
   }

-Shinu.
0
Rekha Kardam
Top achievements
Rank 1
answered on 01 Apr 2011, 04:48 PM
thanks shinu for your reply
but my scenario is little bit different.
my popup window is not radwindow, i have another aspx form and i am opening the popup window using client side function window.showmodaldialog .and get their return value.

i also need to update my grid control values in edit mode from the popup window value in server side not in client side.
we have to eliminate the javascript as per my client need.

please help.
0
Diego
Top achievements
Rank 1
answered on 18 Nov 2014, 01:54 AM
Did you ever figure this out? I am having the same problem
Tags
Grid
Asked by
Mukesh
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Mukesh
Top achievements
Rank 1
Rekha Kardam
Top achievements
Rank 1
Diego
Top achievements
Rank 1
Share this question
or