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

Dynamic ObjectDataSource bound to Grid

2 Answers 281 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Neil
Top achievements
Rank 1
Neil asked on 28 Jan 2013, 07:49 PM
In my application, I have a RadGrid with similar functionality as:

http://demos.telerik.com/aspnet-ajax/grid/examples/overview/defaultcs.aspx#qsf-demo-source

However, I am using ObjectDataSources and referencing a SelectMethod instead of a query to get data.  Example:

<asp:ObjectDataSource SelectMethod="GetDetails"
              TypeName="Details"
              ID="DataSource2"
              runat="server"
              OnSelecting="DataSource2_Selecting">

My problem is that the GetDetails method takes an ObjectId (as a string) to retrieve data for that row item.  Is it possible to fire an event on the expansion of a node (in the grid) so that I can grab it's ObjectId field (column in the grid) and pass it to the method?

Using the OnSelecting parameter, I am able to specify a static string ObjectId:

protected void DataSource2_Selecting (object sender, ObjectDataSourceSelectingEventArgs e)
{
    e.InputParameters["ObjectId"] = "00000000-0000-0000-0000-00000000";
}


However, I need this to be more dynamic and somehow (either through a hidden field, lookup of some kind, etc), find which row's node was expanded, and use that ObjectId, instead of the current static string.

2 Answers, 1 is accepted

Sort by
0
Accepted
Radoslav
Telerik team
answered on 31 Jan 2013, 12:02 PM
Hello Neil,

You can try using a asp:HiddenField or hidden asp:Label like in the following online example:
http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/nestedviewtemplate/defaultcs.aspx
The label with the following declaration is used as a select control parameter for the second sql datasource (in your case this could be the ObjectDatSource):
<asp:Label ID="Label1" Font-Bold="true" Font-Italic="true" Text='<%# Eval("EmployeeID") %>'  Visible="false" runat="server"></asp:Label>
...
 
<asp:SqlDataSource ID="SqlDataSource2" … >
       <SelectParameters>
          <asp:ControlParameter ControlID="Label1" PropertyName="Text" Type="String" Name="EmployeeID">
          </asp:ControlParameter>
       </SelectParameters>
</asp:SqlDataSource>

Please give it try and let me know if it helps you.

All the best,
Radoslav
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
Neil
Top achievements
Rank 1
answered on 31 Jan 2013, 03:04 PM
Thanks Radoslav,

This solutions works well for my purposes.
Tags
Grid
Asked by
Neil
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Neil
Top achievements
Rank 1
Share this question
or