473,406 Members | 2,390 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,406 software developers and data experts.

display list in gridview

i want to dispaly generic list in grid view. in asp.net
i m using this code

Expand|Select|Wrap|Line Numbers
  1. SqlConnection con = new SqlConnection(@"Data Source= HOME-B28AEA71FF; Initial Catalog= Hospital Management; Integrated Security= TRUE");
  2.         con.Open();
  3.         SqlCommand cmd = new SqlCommand("Select Patient_ID,Patient_FName,Patient_LName,Father_Name,Guardian_ID,Admit,Ward_ID,Room_ID,Bed_ID,Refer_doctor,Admission_date,Doctor_fee,Room_type from Admission_Detail", con);
  4.         SqlDataReader rdr = cmd.ExecuteReader();
  5.         do
  6.         {
  7.             while (rdr.Read())
  8.             {p_id=rdr[0].ToString();
  9.  
  10.                 f_Name = rdr[1].ToString();
  11.                 l_Name = rdr[2].ToString();
  12.                 fa_Name = rdr[3].ToString();
  13.  
  14.                 g_Id = rdr[4].ToString();
  15.                 adm = Convert.ToBoolean(rdr[5]);
  16.                 w_Id = rdr[6].ToString();
  17.                 r_Id = Convert.ToInt32(rdr[7]);
  18.                 b_Id = Convert.ToInt32(rdr[8]);
  19.                 ref_doc = rdr[9].ToString();
  20.                 adm_date = rdr[10].ToString();
  21.                 doc_Fee = Convert.ToInt32(rdr[11]);
  22.                 room_typ = rdr[12].ToString();
  23.                 Admission_Detail adm_detail = new Admission_Detail(p_id, f_Name, l_Name, fa_Name, g_Id, adm, w_Id, r_Id, b_Id, ref_doc, adm_date, doc_Fee, room_typ);
  24.                 list.Add(adm_detail);
  25.             }
  26.         } while (rdr.NextResult());
  27.  
  28.         con.Close();
  29.  
  30.         GridView1.DataSource = list;
  31.         GridView1.DataBind();
///////////////
i m getting this error

The data source for GridView with id 'GridView1' did not have any properties or attributes from which to generate columns. Ensure that your data source has content.
////////
note that i m using prperties nor variable.don't tell me that
Expand|Select|Wrap|Line Numbers
  1. public int doc_Fee
  2.     {
  3.         get
  4.         {
  5.             return _doc_Fee;
  6.         }
  7.         set
  8.         {
  9.             value = _doc_Fee;
  10.         }
  11.     }
May 31 '10 #1
3 2215
Frinavale
9,735 Expert Mod 8TB
Does your "Admission_Detail" class have any properties?
Did you specify that the GridView should AutoGenerateColumns?
May 31 '10 #2
@Frinavale
no it has variables same that i have made properties in this class.
do i have to make them properties as well????
yes i have autogenerationcolumn=true
Jun 1 '10 #3
Frinavale
9,735 Expert Mod 8TB
Well I'm not sure what you're doing wrong...but in the above posted property, in the "set" method you are setting value=_doc_Fee....I'm not sure why you're doing that. You should be setting _doc_Fee = value.

This is what I tested and it works fine....

The GridView:
Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="testGrid" runat="server" ForeColor="#333333" GridLines="Horizontal"
  2.     CellPadding="4" AutoGenerateColumns="true">
  3.     <RowStyle BackColor="#F7F6F3" ForeColor="#000000" />
  4.     <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
  5.     <HeaderStyle BackColor="#284775" ForeColor="AliceBlue" Font-Bold="true" />
  6. </asp:GridView>

The C# code:
Expand|Select|Wrap|Line Numbers
  1. namespace WebApplication2
  2. {
  3.   public partial class _Default : System.Web.UI.Page
  4.   {
  5.     protected void Page_PreRender(object sender, EventArgs e)
  6.     {
  7.       testGrid.DataSource = retrieveFooSource();
  8.       testGrid.DataBind();
  9.     }
  10.     private List<Foo> retrieveFooSource() {
  11.         List<Foo> source = new List<Foo>();
  12.         if (HttpContext.Current.Session["FooSource"] != null)
  13.         {
  14.             source = (List<Foo>)HttpContext.Current.Session["FooSource"];
  15.         }
  16.         else
  17.         {
  18.             String[] names = { "Bob", "Sally", "Frank", "Steve", "Beth", "Pat", "Joan", "Howard" };
  19.  
  20.             int i = 0;
  21.             foreach (string name in names)
  22.             {
  23.                 source.Add(new Foo(name,i+100,DateTime.Today.Date));
  24.                 i++;
  25.             }
  26.         }
  27.  
  28.         HttpContext.Current.Session["FooSource"] = source;
  29.         return source;
  30.     }
  31.  
  32.     private class Foo {
  33.         private int _doc_Fee;
  34.         private DateTime _doc_Date;
  35.         private string _doc_name;
  36.         public int doc_Fee {
  37.             get { return _doc_Fee; }
  38.             set { _doc_Fee = value; }
  39.         }
  40.         public DateTime doc_Date{
  41.             get { return _doc_Date; }
  42.             set { _doc_Date = value; }
  43.         }
  44.         public string doc_Name {
  45.             get { return _doc_name; }
  46.             set { _doc_name = value; }
  47.         }
  48.         public Foo(string name, int fee, DateTime date) {
  49.             _doc_Fee = fee;
  50.             _doc_name = name;
  51.             _doc_Date = date;
  52.         }
  53.     }
  54.   }
  55. }
Jun 1 '10 #4

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

Similar topics

0
by: coli | last post by:
I've run into a very odd problem... I've overwriten LoadPageStateFromPersistenceMedium and SavePageStateToPersistenceMedium in order to store the page's viewstate into the session. This is so...
1
by: keithb | last post by:
Is there a way to make a GridView header row invisible? Thanks, Keith
3
by: mercea | last post by:
hi, i need help! i am developing a web application where the user inputs some data via textboxes and it is saved in a database. i have written the following code to pass the parameter values...
0
by: silpa | last post by:
Hi, I have a table with one field. filed name----Picture datatype---- image I am using c#.net and asp.net 2.0. 1.How to upload image using fileupload into the database...
2
by: J055 | last post by:
Hi I need to search a number of DataTables within a DataSet (with some relationships) and then display the filtered results in a GridView. The Columns that need to be displayed come from 2 of...
1
by: tuman | last post by:
I am making a project which is related to classified web site. I have used a gridview control. In which put some sqltable data. And i want to show a image which is store in my project folder,...
6
by: jaredciagar | last post by:
Hi Guys Can you help me please in my project, I have tblItemList in my SQL DB. I want to display all the data in my tblItemList in GridView control.... How Can I Do That in VB Script using VB.Net......
1
by: zlf | last post by:
For tables with large number of rows, it is difficult to access the rows with high page number due to high volume of data. Currently the user is required to click the "..." link many times to get...
1
by: vineetbindal | last post by:
Hi all, I have a datagrid and detailsview. when a user selects a row in datagrid onSelectedIndexchanged is fired and Detailsview comes into picture. I want to display the data of the selected row...
3
by: btreddy | last post by:
Hiii experts , I've received one critical requirement from my customer this morning. I've a gridview,in one of my webpage, which displays all the prticipants who are participating in a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.