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

On Click of button which is outside radgrid, Read value of dynamically created textbox on Itemdatabound event

3 Answers 219 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shradha
Top achievements
Rank 1
Shradha asked on 01 Aug 2012, 05:49 AM
Hi,

I have "save" button outside of radgid.

I am adding textbox in radgrid template column on ItemDatabound event.

I want to read textbox value when i will click on "save" button

Please guid how to do access this.

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 01 Aug 2012, 06:00 AM
Hello,

You can add the controls in ItemCreated event and access in an external button click event as shown below.
C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
   if (e.Item is GridDataItem)
   {
     GridDataItem item = (GridDataItem)e.Item;
     TextBox txt = new TextBox();
     txt.ID = "TextBox1";
     item["TemplateColumn"].Controls.Add(txt);
   }
}
protected void Button2_Click(object sender, EventArgs e)
{
  foreach (GridDataItem item in RadGrid1.Items)
  {
      TextBox txt = (TextBox)item.FindControl("TextBox1");
      string value = txt.Text;
  }
}

Thanks,
Shinu.
0
Shradha
Top achievements
Rank 1
answered on 01 Aug 2012, 10:58 AM
Thanks this is working.

I am facing one more issue.

1. I have two rad grids
2. I drag selected item from "radgrid1" and drop it to "radgrid2"
3. Whenever i drop item to "radgrid2" already existing items get refresh.(Every item/row having textbox control whatever entered value in textbox gets empty after dropping new item)
0
Eyup
Telerik team
answered on 06 Aug 2012, 10:24 AM
Hello Shradha,

Could you please check out the following demo and verify that the problem could be reproduced using it?
 Grid / Items Drag-and-drop

One possible approach would be to save the entered text in the created Session or ViewState, or create a new Session to hold a HashTable with the DataKeyID of the row and the current text of the related textbox. Therefore, you will be able to restore the entered text by traversing the items as demonstrated in the first reply.

I hope this helps.

Greetings,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Shradha
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Shradha
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or