i want to dispaly generic list in grid view. in asp.net
i m using this code - SqlConnection con = new SqlConnection(@"Data Source= HOME-B28AEA71FF; Initial Catalog= Hospital Management; Integrated Security= TRUE");
-
con.Open();
-
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);
-
SqlDataReader rdr = cmd.ExecuteReader();
-
do
-
{
-
while (rdr.Read())
-
{p_id=rdr[0].ToString();
-
-
f_Name = rdr[1].ToString();
-
l_Name = rdr[2].ToString();
-
fa_Name = rdr[3].ToString();
-
-
g_Id = rdr[4].ToString();
-
adm = Convert.ToBoolean(rdr[5]);
-
w_Id = rdr[6].ToString();
-
r_Id = Convert.ToInt32(rdr[7]);
-
b_Id = Convert.ToInt32(rdr[8]);
-
ref_doc = rdr[9].ToString();
-
adm_date = rdr[10].ToString();
-
doc_Fee = Convert.ToInt32(rdr[11]);
-
room_typ = rdr[12].ToString();
-
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);
-
list.Add(adm_detail);
-
}
-
} while (rdr.NextResult());
-
-
con.Close();
-
-
GridView1.DataSource = list;
-
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 -
public int doc_Fee
-
{
-
get
-
{
-
return _doc_Fee;
-
}
-
set
-
{
-
value = _doc_Fee;
-
}
-
}
3 2215
Does your "Admission_Detail" class have any properties?
Did you specify that the GridView should AutoGenerateColumns?
@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
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: - <asp:GridView ID="testGrid" runat="server" ForeColor="#333333" GridLines="Horizontal"
-
CellPadding="4" AutoGenerateColumns="true">
-
<RowStyle BackColor="#F7F6F3" ForeColor="#000000" />
-
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
-
<HeaderStyle BackColor="#284775" ForeColor="AliceBlue" Font-Bold="true" />
-
</asp:GridView>
The C# code: -
namespace WebApplication2
-
{
-
public partial class _Default : System.Web.UI.Page
-
{
-
protected void Page_PreRender(object sender, EventArgs e)
-
{
-
testGrid.DataSource = retrieveFooSource();
-
testGrid.DataBind();
-
}
-
private List<Foo> retrieveFooSource() {
-
List<Foo> source = new List<Foo>();
-
if (HttpContext.Current.Session["FooSource"] != null)
-
{
-
source = (List<Foo>)HttpContext.Current.Session["FooSource"];
-
}
-
else
-
{
-
String[] names = { "Bob", "Sally", "Frank", "Steve", "Beth", "Pat", "Joan", "Howard" };
-
-
int i = 0;
-
foreach (string name in names)
-
{
-
source.Add(new Foo(name,i+100,DateTime.Today.Date));
-
i++;
-
}
-
}
-
-
HttpContext.Current.Session["FooSource"] = source;
-
return source;
-
}
-
-
private class Foo {
-
private int _doc_Fee;
-
private DateTime _doc_Date;
-
private string _doc_name;
-
public int doc_Fee {
-
get { return _doc_Fee; }
-
set { _doc_Fee = value; }
-
}
-
public DateTime doc_Date{
-
get { return _doc_Date; }
-
set { _doc_Date = value; }
-
}
-
public string doc_Name {
-
get { return _doc_name; }
-
set { _doc_name = value; }
-
}
-
public Foo(string name, int fee, DateTime date) {
-
_doc_Fee = fee;
-
_doc_name = name;
-
_doc_Date = date;
-
}
-
}
-
}
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
by: keithb |
last post by:
Is there a way to make a GridView header row invisible?
Thanks,
Keith
|
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...
|
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...
|
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...
|
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,...
|
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......
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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,...
| |