473,320 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

GridView in a user control

149 100+
Hi,

I'm sure this is very basic but I'm having a problem with GridView in a user control.

The codebehind is calling data from a strongly typed list and binding it to the gridview control but when I test the page nothing appears.

Expand|Select|Wrap|Line Numbers
  1. protected void Page_Load(object sender, EventArgs e)
  2.         {
  3.             String pageId = Page.GetType().Name;
  4.             pageId = pageId.Replace("_aspx", "");
  5.             String compType = "featureComponent";
  6.             List<ComponentDetails> component = new List<ComponentDetails>(ComponentInfo.GetComponentFromCache(pageId, compType));
  7.             fComp.DataSource = component;
  8.             fComp.DataBind();
  9.         }
I also get a debug error fComp name doesn't exist.....

I have tried using this but still get an error;

Expand|Select|Wrap|Line Numbers
  1. protected System.Web.UI.WebControls.GridView fComp;
But no luck. Would appreciate any help!
Jul 16 '07 #1
6 1779
nateraaaa
663 Expert 512MB
Hi,

I'm sure this is very basic but I'm having a problem with GridView in a user control.

The codebehind is calling data from a strongly typed list and binding it to the gridview control but when I test the page nothing appears.

Expand|Select|Wrap|Line Numbers
  1. protected void Page_Load(object sender, EventArgs e)
  2.         {
  3.             String pageId = Page.GetType().Name;
  4.             pageId = pageId.Replace("_aspx", "");
  5.             String compType = "featureComponent";
  6.             List<ComponentDetails> component = new List<ComponentDetails>(ComponentInfo.GetComponentFromCache(pageId, compType));
  7.             fComp.DataSource = component;
  8.             fComp.DataBind();
  9.         }
I also get a debug error fComp name doesn't exist.....

I have tried using this but still get an error;

Expand|Select|Wrap|Line Numbers
  1. protected System.Web.UI.WebControls.GridView fComp;
But no luck. Would appreciate any help!
In the Design view of your user control what name is assigned to your gridview? Make sure that the gridview id= fComp.

Nathan
Jul 16 '07 #2
rsdev
149 100+
Hi,

Yep! My gridview has id=fComp. If I create a list item on the codebehind page it appears no problem so it must be an error in my BLL tier.

Here's the BLL;

Expand|Select|Wrap|Line Numbers
  1. public static List<ComponentDetails> GetComponentFromCache(string pageId, string compType)
  2.         {
  3.             List<ComponentDetails> component = null;
  4.             string key = "Component_" + pageId;
  5.  
  6.             if (BizObject.Cache[key] != null)
  7.             {
  8.                 component = (List<ComponentDetails>)BizObject.Cache[key];
  9.             }
  10.             else
  11.             {
  12.                 component = ComponentData.GetComponentById(pageId, compType);
  13.                 BaseCache.CacheData(key, component);
  14.             }
  15.             return component;
  16.         }
And then here's the DAL it's calling;

Expand|Select|Wrap|Line Numbers
  1. public static List<ComponentDetails> GetComponentById(string pageId, string compType)
  2.         {
  3.             using (SqlConnection conn = new SqlConnection(strConnect))
  4.             {
  5.                 SqlConnection cn = GetConnection();
  6.                 SqlCommand oCommand = new SqlCommand("GetComponent", cn);
  7.                 oCommand.CommandType = CommandType.StoredProcedure; // Parametrs
  8.                 oCommand.Parameters.Add("@page_id", SqlDbType.VarChar).Value = pageId;
  9.                 oCommand.Parameters.Add("@comp_type", SqlDbType.VarChar).Value = compType;
  10.                 cn.Open();
  11.                 IDataReader reader = ExecuteReader(oCommand, CommandBehavior.SingleRow);
  12.                 if (reader.Read())
  13.                     return DisplayListComponent(reader);
  14.                 else
  15.                     return null;
  16.             }
  17.         }
  18.  
  19.         private static ComponentDetails DisplayComponent(IDataReader reader)
  20.         {
  21.             ComponentDetails component = new ComponentDetails(
  22.                reader["textField"].ToString(), 
  23.                (bool)reader["approved"],
  24.                reader["title"].ToString(),
  25.                reader["type"].ToString(),
  26.                reader["source"].ToString(),
  27.                reader["width"].ToString(),
  28.                reader["height"].ToString(),
  29.                reader["link"].ToString(),
  30.                reader["header"].ToString(),
  31.                reader["hypertitle1"].ToString(),
  32.                reader["hyperlink1"].ToString(),
  33.                reader["hypertitle2"].ToString(),
  34.                reader["hyperlink2"].ToString(),
  35.                reader["hypertitle3"].ToString(),
  36.                reader["hyperlink3"].ToString(),
  37.                (int)reader["number_links"]);
  38.  
  39.             return component;
  40.         }
  41.         private static List<ComponentDetails> DisplayListComponent(IDataReader reader)
  42.         {
  43.             List<ComponentDetails> component = new List<ComponentDetails>();
  44.             while (reader.Read())
  45.                 component.Add(DisplayComponent(reader));
  46.             return component;
  47.         }
Then I have a strongly typed details file which checks out ok. Any further help would be great is I'm stuck here.
Jul 16 '07 #3
Plater
7,872 Expert 4TB
Have you tried just printing out all your results to a textbox or something?

Also, does your design for the GridView contain specifics on what to do on an empty dataset? Like I tell mine to maintain some colorizations and have it say "(none)" in them
Jul 16 '07 #4
rsdev
149 100+
Hi Plater,

I just added an EmptyDataTemplate and recieved the announcement on testing in the browser. So myData isn't getting through. That's great at least I know the problem is probably in BLL. My BLL was working fine until I decided to change it to a strongly typed List<> and now there are no reported errors and no data.

It's the first time I've tried converting datareader to a list I'm sure this is where the problem.

The BLL and DAL code are above if there's any obvious problems there please let me know.

Appreciate the help.
Jul 16 '07 #5
Plater
7,872 Expert 4TB
I generally don't use the List object so I'm not to clear on its usage.

Are you doing anything besides binding the data to the gridview? If not, why not just use the DataAdapter object and use it to create a DataTable for the datasource?

Expand|Select|Wrap|Line Numbers
  1. DataTable retval=new DataTable();
  2. string myq="";
  3. //populate myq with your SQL select statement
  4. SqlDataAdapter dba = new SqlDataAdapter(myq, myDataBaseConnection);
  5. dba.Fill(retval);
  6.  
Jul 16 '07 #6
rsdev
149 100+
I'm using thebeerhouse nTier architecture which uses ObjectDataSource to bind a BLL method to the gridview. Thebeerhouse uses Datareaders which then parse to a list object and then updates the Cache, but I think it's becoming to complex for me to work out how to bind this data.

So I've dumped my codebehind and am using the ObjectDataSource to get the method but it still isn't producing any results in the gridview.

I've set up a test gridview and used the built in functions of Visual Web Developer to acces my stored procedure and all works well. But then I don't have the benefit of use the Cache method that I've set up.

Basically I'm going to have to dump thebeerhouse and start again on my own. Scary! And also a week behind. My heart sinks.

Thanks again for your efforts.
Jul 16 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum....
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
5
by: Dick | last post by:
I have a GridView bound to an ObjectDataSource. I have a Button that calls GridView.DataBind. I want the row that is selected before the DataBind to still be selected afterwards. This happens...
1
by: Giovanni | last post by:
Dear Friends/Gurus, I have exhausted myself and have yet no solution to the following: I have an ASP.NET 2.0 Survey type application. On a page, I have placed a GridView which is bound to an...
0
by: bsaran | last post by:
Hi, I have a code that sort of works. The event flow is as follows: In a user control of type "FilterControl" user selects certain values from 3 related dropdown lists. (two of them have auto...
0
by: John Smith | last post by:
ASP.Net 2.0 / C# / IIS 6 I have 2 pages. The master page consists of a tabbed menu created using the Menu and MultiView controls. Something like this: ...
0
by: John Smith | last post by:
If anyone can help, I would very muchly appreciate it. I have a main page that uses the .net 2.0 menu control with the multiview controls as the menu choices. This works fine. One of the menu...
1
by: Stan SR | last post by:
Hi, I use a user control within a gridview Something like this <asp:GridView DataSourceID="myDatasource" ID="gvList" runat="server"> <Columns> <asp:TemplateField> <ItemTemplate>...
4
by: Jeff | last post by:
Hi, I have a ASP.NET 2.0 Web Application. Many of the pages use the ASP.NET GridView with paging and sorting. One of the columns of this Gridview is a template column (LinkButton). The data being...
2
by: =?Utf-8?B?UGF1bA==?= | last post by:
I have a gridview with 2 columns. One column is a BoundColumn to a part number (string). One column is an ItemTemplate with a FileUpload control. There can be multiple rows (i.e. part numbers)...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.