Programmatic Declare SessionParameters for AspSqlDataSource

2 posts, 0 answers
  1. Bruno
    Bruno avatar
    26 posts
    Member since:
    Feb 2009

    Posted 23 Mar 2009 Link to this post

    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"
            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"); 
                //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; 

    And I´m Calling with:

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

  2. Todd
    Todd avatar
    66 posts

    Posted 26 Mar 2009 Link to this post

    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// title~3d~22Vote For Telerik Products~22 alt~3d~22Vote For Telerik Products~22 src~3d~22http~3a// /~3e~3c/a~3e~3cbr /~3e Check out ~3ca href~3d~22http~3a// 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
Back to Top