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

RadGrid Open Popup "Add New" Form and Pouplate TextBox

4 Answers 342 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shawn
Top achievements
Rank 1
Shawn asked on 17 May 2013, 06:39 PM
Hello,

I've looked throughout this forum, but I was not able to find the answer to my problem.

I am tasked to open the EditMode of a RadGrid in the codebehind for a webform to add a new item and this is what I use:

RadGrid1.MasterTableView.InsertItem();

The "EditMode" of the RadGrid is set to "PopUp", and the code above works just fine.  It opens the popup form if I were to put the code above in the click event of a button or Page_Load, for example.

My problem is that I have to send a value to an ASP text box in a databound template column within this popup "Edit" form from another page, but I'm unable to gain access to the template Item's text box on the popup edit form.

So, basically the steps would be like so:
1- the user clicks a link on a separate page, and either through session or querytring a value is sent to the page that contanins my RadGrid1.
2- the page containing the RadGrid1 opens, and the popup edit form is already open with the text of the querystring or session variable visible within the "AnnouncementsTextBox" textbox.

How do I go about populating the text box in the popup edit form?

Any help would be very much appreciated.

Here's the code for the template column:
<Columns>
     <telerik:GridTemplateColumn DataField="Announcements" UniqueName="AnnouncementsText">
          <EditItemTemplate>
              <asp:TextBox ID="AnnouncementsTextBox" runat="server" Text='<%# Bind("Announcements") %'></asp:TextBox>
          </EditItemTemplate>
          <ItemTemplate>
              <asp:Label ID="AnnouncementsLabel" runat="server" Text='<%# Eval("Announcements") %'></asp:Label>
          </ItemTemplate>
      </teleric:GridTemplateColumn>
</Columns>


Here's the code I've tried to use to set the value in the textbox:
foreach (GridDataItem item in RadGrid.Items)
{
   TextBox tb = (TextBox)item.FindControl("AnnouncementTextBox");
   tb.Text = "This is where the QueryString text would go.";
}

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 20 May 2013, 05:30 AM
Hi Shawn,

 Please try this code to access the value in EditItemtemplate .

C#:
foreach (GridEditableItem item in RadGrid1.EditItems)
{
  TextBox txt = item.FindControl("AnnouncementsTextBox") as TextBox;
        txt.Text= your value
}

Thanks,
Princy
0
Shawn
Top achievements
Rank 1
answered on 20 May 2013, 11:33 AM
Thanks for the response Princy,

I've put the code you provided in the "onItemEvent" code for the RadGrid.  When the popup window opens the "onItemEvent" does fire, but the foreach procedure never gets to the find control line.  It's as if it doesn't find any editable items.

is "onItemEvent" the wrong place to put this code?

Thanks.
0
Elliott
Top achievements
Rank 2
answered on 20 May 2013, 05:10 PM
try the OnItemDataBound event
0
Princy
Top achievements
Rank 2
answered on 21 May 2013, 07:58 AM
Hello Shawn,

Please try the code in OnItemDataBound event.

C#:
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
       {
           GridEditableItem edit = (GridEditableItem)e.Item;
           TextBox txt = edit.FindControl("AnnouncementsTextBox") as TextBox;
           txt.Text = your value;
       }

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