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

Reference a control in the CommandItemTemplate from the NeedDataSource event

5 Answers 252 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 26 Jan 2012, 03:15 PM
Hi, 
I've got a checkbox in the <CommandItemTemplate>
In the NeedDataSource event, I'm trying to capture whether the checkbox is checked

Can anyone tell me how to reference this checkbox control ?

Thanks :)

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 27 Jan 2012, 05:00 AM
Hello Scott,

You can reference the controls in ItemDataBound event. ItemDataBound is fired only when grid binds to data. Here is the sample code.
C#:
protected void grid_ItemDataBound(object sender, GridItemEventArgs e)
{
  if (e.Item is GridCommandItem)
 {
  GridCommandItem item = (GridCommandItem)e.Item;
  CheckBox chk = (CheckBox)item.FindControl("CheckBox1");
  }
}

-Shinu.
0
Miky
Top achievements
Rank 1
answered on 25 Oct 2012, 12:08 PM
I have this exact same problem, but in my case it's a RadComboBox.  It's important that I get the value in the NeedDataSource event because this decide which databinding i'm doing as of the "Select"...

The RadComboBox works perfectly, and teh data is filled and kept between each postback, but i dunno how to go get my value.

Regards,
0
Eyup
Telerik team
answered on 30 Oct 2012, 11:17 AM
Hi Michel,

NeedDataSource event fires too early in the control's lifecycle in order to get the command item. Therefore, you will need to use a Session or ViewState variable to save the selected item's value. Another approach would be to try the following:
http://www.telerik.com/help/aspnet-ajax/grid-changing-structure-dynamically.html

I hope this will prove helpful.

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.
0
Miky
Top achievements
Rank 1
answered on 31 Oct 2012, 11:31 AM
Hi

Thnx for the answer.

Since I can't use the session in this case (too long to explain) do you have an example of how I would do it with the viewstate ?

Kind regards,

Michel
0
Eyup
Telerik team
answered on 05 Nov 2012, 11:07 AM
Hello Michel,

I have created a sample RadGrid web site where I implemented the described functionality. Could you please check out the attached application and let me know about the result?

Kind regards,
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
Scott
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Miky
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or