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

RadGrid Programatically

3 Answers 49 Views
Grid
This is a migrated thread and some comments may be shown as answers.
talal
Top achievements
Rank 1
talal asked on 21 May 2010, 11:41 PM
i saw many posts about this but none seemed fixing my issue.

I have a ASP:PlaceHolder (ph).

I thought this would work fine:

 

        protected void Page_Load(object sender, EventArgs e)  
        {  
            SqlDataSource ds = new SqlDataSource();  
            ds.ConnectionString = "Data Source=HNT;Initial Catalog=dbL;Persist Security Info=True;User ID=usB;Password=xxx";  
            ds.SelectCommand = "SELECT aID,AName FROM tbl where LID=36";  
            ds.InsertCommand = "INSERT INTO tbl (LID, AName) VALUES (12, 'Test')";  
              
            Telerik.Web.UI.RadGrid rg = new Telerik.Web.UI.RadGrid();  
            rg.DataSource = ds;  
            rg.MasterTableView.DataKeyNames = new string[] { "aID" };  
            rg.MasterTableView.AllowAutomaticDeletes = true;  
            rg.MasterTableView.AllowAutomaticInserts = true;  
            rg.MasterTableView.AllowAutomaticUpdates = true;  
 
            rg.MasterTableView.CommandItemDisplay = Telerik.Web.UI.GridCommandItemDisplay.Top;  
 
 
 
            ph.Controls.Add(rg);  
         }  
 

The values of insert are hard coded for simplicity (it does not work niether with values nor with parameters).
The grid displays fine as expected.
When i hit the insert it shows the insert form as expected.

However when i ctry to save the form (by hitting the insert button) it does not post the command.
No error, and even tried putting an event for inserting but it does not seem to fire at all.

am i missing something?

thank you

3 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 26 May 2010, 01:54 PM
Hi Talal,

Could you please try to move the logic from Page_Load to the Page_Init event. When generating RadGrid instance entirely in code, you should use the Page_Init event handler. Also, please check out the following online documentation article which explains how to create a RadGrid programmatically:
http://www.telerik.com/help/aspnet-ajax/grdprogrammaticcreation.html

I hope this helps.


Best wishes,
Radoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
talal
Top achievements
Rank 1
answered on 26 May 2010, 07:35 PM
I tried onInit event and that did not help either.
I checked the documentation and the link yuo provided already and i could not get my code to work.

Could you please try the code i provided and see if you can get it to work?

Thank you
0
Radoslav
Telerik team
answered on 28 May 2010, 03:31 PM
Hi Talal,

I tried to reproduce the described issue, but to no avail. I am sending you a simple example, based on your code, which demonstrates the desired functionality. Please check it out and let me know what differs in your case.

Regards,
Radoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
talal
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
talal
Top achievements
Rank 1
Share this question
or