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

Programmatic Declare SessionParameters for AspSqlDataSource

1 Answer 35 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bruno
Top achievements
Rank 1
Bruno asked on 23 Mar 2009, 08:01 PM
I need to create dynamically  a Grid strutucture with 3 level hyerarchy

how can I set the SessionParameters in C#

my code is looking like:

private void DefineGridStructure(string VQuery1,string VDataKey1,string VQuery2,string VDataKey2) 
    { 
 
        string connString = ConfigurationManager.ConnectionStrings["coelbaConnectionString"].ConnectionString; 
                 
        SqlDataSource DataSource1 = new SqlDataSource(connString, VQuery1.ToString()); 
        DataSource1.ID = "SqlDataSource1"
        this.PlaceHolder1.Controls.Add(DataSource1); 
         
        RadGrid RadGrid1 = new RadGrid(); 
 
        RadGrid1.ID = "RadGrid1"
        RadGrid1.DataSourceID = "SqlDataSource1"
 
        RadGrid1.MasterTableView.DataKeyNames = new string[] { VDataKey1 }; 
        RadGrid1.Width = Unit.Percentage(98); 
        RadGrid1.PageSize = 40; 
        RadGrid1.AllowPaging = true
        RadGrid1.AllowSorting = true
        RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric; 
        RadGrid1.PagerStyle.Position = GridPagerPosition.TopAndBottom; 
        RadGrid1.PagerStyle.NextPagesToolTip = "Próximas páginas"
        RadGrid1.PagerStyle.PrevPagesToolTip = "Páginas anteriores"
        RadGrid1.PagerStyle.NextPageText = "Próxima página"
        RadGrid1.PagerStyle.PrevPageToolTip = "Página Anterior"
        RadGrid1.AutoGenerateColumns = true
        RadGrid1.ShowStatusBar = true
        RadGrid1.ShowFooter = true
        RadGrid1.Skin = "Sunset"
         
        RadGrid1.MasterTableView.PageSize = 40; 
        RadGrid1.MasterTableView.AllowMultiColumnSorting = true
 
        if (VQuery2 != ""
        { 
 
            SqlDataSource DataSource2 = new SqlDataSource(connString, VQuery2); 
            DataSource2.ID = "SqlDataSource2"
            SessionParameter nummes = new SessionParameter("@nummes", System.Data.DbType.Int32,"nummes"); 
            DataSource2.SelectParameters.Add(nummes); 
            this.PlaceHolder1.Controls.Add(DataSource2); 
 
 
            //Detail table - Orders (II in hierarchy level) 
            GridTableView tableViewOrders = new GridTableView(RadGrid1); 
            tableViewOrders.DataSourceID = "SqlDataSource2"
            tableViewOrders.Width = Unit.Percentage(100); 
 
            tableViewOrders.DataKeyNames = new string[] { VDataKey2 }; 
            tableViewOrders.AutoGenerateColumns = true
 
            GridRelationFields relationFields = new GridRelationFields(); 
            relationFields.MasterKeyField = VDataKey1; 
            relationFields.DetailKeyField = VDataKey1; 
            tableViewOrders.ParentTableRelation.Add(relationFields); 
 
            RadGrid1.MasterTableView.DetailTables.Add(tableViewOrders); 
 
            
        } 
 
 
        this.PlaceHolder1.Controls.Add(RadGrid1); 
    } 


And I´m Calling with:

DefineGridStructure("exec sp_totalAnoMes""nummes""exec sp_relPorData""datakey"); 
But the parameters are not being supplied.






1 Answer, 1 is accepted

Sort by
0
Todd
Telerik team
answered on 26 Mar 2009, 08:44 PM
Hello Bruno~2c~3cbr /~3e ~3cbr /~3e I~27m sorry to hear you~27re having trouble with the RadGrid and data binding. Let me see if I can help.~3cbr /~3e ~3cbr /~3e It sounds like the main challenge you~27re having is setting parameters on your declarative data source controls. In general~2c when you set parameters for a SqlDataSource~2c you do not need to include the ~22@~22 symbol in front of the parameter name. The data control will automatically try to append a ~22@~22 sign to your parameter names.~3cbr /~3e ~3cbr /~3e Try removing the ~22@~22 from ~22@nummes~22 and see if that helps. Otherwise~2c your scenario should work assuming you are placing a value in Session that matches the session key you specify. If you continue to have trouble~2c let me know and I~27ll be happy to send a working demo project.~3cbr /~3e ~3cbr /~3e Thanks~21~3cbr /~3e -Todd ~3cdiv style~3d~22font-size~3a 10px~3b padding-top~3a 10px~3b~22~3e ~3ca href~3d~22http~3a//www.aspnetpro.com/awards/default.asp~22~3e~3cimg title~3d~22Vote For Telerik Products~22 alt~3d~22Vote For Telerik Products~22 src~3d~22http~3a//www.telerik.com/images/Forum/VoteIn.jpg~22 /~3e~3c/a~3e~3cbr /~3e Check out ~3ca href~3d~22http~3a//www.telerik.com/support/teleriktrainer.aspx~22 target~3d~22_blank~22 style~3d~22color~3a gray~3b~22~3e Telerik Trainer~3c/a~3e ~2c the state of the art learning tool for Telerik products. ~3c/div~3e
Tags
Grid
Asked by
Bruno
Top achievements
Rank 1
Answers by
Todd
Telerik team
Share this question
or