I have created a page with a Master / Detail pair of grids with the help of the excellent tutorial here on the Telerik site.
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/selectedvalue/defaultcs.aspx
I got this working fine from the start. I have the top row in the grid highlighting when the page loads and the details grid responds with the correct data for that grid. Selecting another row on the master works the same way. The details grid updates and joy and happiness abound. :)
The top grid has a simple SqlDataSource that looks like this.
As you can see I am hardcoding the userID. This is my test of the system and it works.
It is when I try to set this dynamically the problems start.
First I deleted the SelectCommand parameter from the SqlDataSource above.
Then in the Page_PreRender of the code behind I do this. .
This works in as much as the correct Locations for that UserID are returned.
However there are 3 problems that appear
I did not bore you with pasting my grids here. Suffice to say they work, as long as I hard code the SelectCommand in the page.
Perhaps Page_PreRender is not the correct place to set the SelectCommand on the data source?
Could someone please shed some light on what is causing this behavior?
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/selectedvalue/defaultcs.aspx
I got this working fine from the start. I have the top row in the grid highlighting when the page loads and the details grid responds with the correct data for that grid. Selecting another row on the master works the same way. The details grid updates and joy and happiness abound. :)
The top grid has a simple SqlDataSource that looks like this.
<
asp:SqlDataSource
ID
=
"dsLocations"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:Database_DB1 %>"
SelectCommand = "select * from GetLocations WHERE loc_User_ID = 44"
ProviderName="System.Data.SqlClient" >
</
asp:SqlDataSource
>
As you can see I am hardcoding the userID. This is my test of the system and it works.
It is when I try to set this dynamically the problems start.
First I deleted the SelectCommand parameter from the SqlDataSource above.
<
asp:SqlDataSource
ID
=
"dsLocations"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:Database_DB1 %>"
ProviderName="System.Data.SqlClient" >
</
asp:SqlDataSource
>
Then in the Page_PreRender of the code behind I do this. .
protected void Page_PreRender(object sender, EventArgs e)
{
dsLocations.SelectCommand = "select * from GetLocations WHERE loc_User_ID = " + user.User_ID.ToString();
if (rgLocations.SelectedIndexes.Count == 0)
{
rgLocations.SelectedIndexes.Add(0);
rgActivities.Rebind();
}
}
This works in as much as the correct Locations for that UserID are returned.
However there are 3 problems that appear
- the first row of the grid is no longer longer highlighted ie:
rgLocations.SelectedIndexes.Add(0);
// fail - the details grid is no longer showing the details for the top row on page load id:
rgActivities.Rebind();
// fail - finally the details grid no longer updates when you select a row from the master table.
I did not bore you with pasting my grids here. Suffice to say they work, as long as I hard code the SelectCommand in the page.
Perhaps Page_PreRender is not the correct place to set the SelectCommand on the data source?
Could someone please shed some light on what is causing this behavior?