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

Edit/update when using a custom sqldatasource

4 Answers 68 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Philip
Top achievements
Rank 1
Philip asked on 29 Apr 2009, 03:41 PM
I need some help on using a custom sqldatasource.

I have created a grid that works with the command buttons for insertion,deletion and updating (taken from the telerik demos).
 
I currently use the sqldatasource created from the user interface. I need to create a dynamic select command. When I use the dynamic command, all functionality with the command buttons cease to work.

Can someone tell me how to use the custom select and keep the functionality of the command buttons?

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 30 Apr 2009, 04:25 AM
Hi Philip,

Here is the sample code to dynamically create Select command for the SqlDataSource .

CS:
 
 string connectionString = "..."
 //Set the parameter value
 string categoryId ="1";
string selectSql = "Select * From Categories WHERE CategoryID = @CategoryID"
 
SqlDataSource1.ConnectionString = connectionString; 
 
SqlDataSource1.SelectCommand = selectSql; 
 
// new Parameter( parameterName, type , Value)
Parameter parameter = new Parameter("CategoryID", TypeCode.Int32, categoryId ); 
 
SqlDataSource1.SelectParameters.Add(parameter); 
 
RadGrid1.DataSourceID="SqlDataSource1";
RadGrid1.DataBind();  


Shinu
0
Philip
Top achievements
Rank 1
answered on 30 Apr 2009, 02:59 PM
Adding the select command is not the problem. The problem is that when I put the select command in the code behind, the Edit/Insert/Delete buttons no longer trigger the respective events. i.e. the edit boxes do not open upon click of the "Edit Selected Items" button.
0
Sebastian
Telerik team
answered on 04 May 2009, 02:19 PM

Hello Philip,

Have you tried generating the SELECT query for the data source control inside the PreRender handler of the grid (inside !Page.IsPostBack conditional block) and invoking the Rebind() method of the control to refresh its state? This should not affect the lifecycle of the grid and the commands from the edit/insert/delete buttons should be raised as expected.

If this does not help, I will appreciate if you paste your code implementation in this forum thread (using the 'Format code block" dialog from the upper right corner of the forum editor). Thus I will do my best to advice you further on how to solve the issue at hand.

Kind regards,

Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Philip
Top achievements
Rank 1
answered on 04 May 2009, 02:22 PM
Thank you. That is the exact solution that I found for myself. Thanks for your help.
Tags
Grid
Asked by
Philip
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Philip
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or