|
I created an ASP.NET project and dropped a DataList on
the web form. I then wrote a simple class to return data:
namespace Playing
{
public class PositionData
{
private string name;
private string ticker;
public PositionData(string name, string ticker)
{
this.name = name;
this.ticker = ticker;
}
public string Name
{
get { return name; }
}
public string Ticker
{
get { return ticker; }
}
}
I then inserted the code to load data into the DataList
private void Page_Load(object sender, System.EventArgs
e)
{
if (!IsPostBack)
{
ArrayList values = new ArrayList();
values.Add(new PositionData("Microsoft", "Msft"));
values.Add(new PositionData("Intel", "Intc"));
values.Add(new PositionData("Dell", "Dell"));
DataList1.DataSource = values;
DataList1.DataBind();
}
}
}
When I run the application into IE 6, All I saw was a
blank screen with no DataList and nada. I try with
DataGrid and everything works fine.
What have I done wrong?
Thank you in advance for all your help. | |
Share:
|
Did you actually bind the columns to the DataList? Unlike the DataGrid, you
must visit the HTML section of the webform and bind the datafield/property
to each column in the list, whereas the datagrid will "draw" the data based
on the datafield property set in the designer.
HTH,
Morgan
"Thanh" <an*******@discussions.microsoft.com> wrote in message
news:03****************************@phx.gbl... I created an ASP.NET project and dropped a DataList on the web form. I then wrote a simple class to return data:
namespace Playing { public class PositionData { private string name; private string ticker;
public PositionData(string name, string ticker) { this.name = name; this.ticker = ticker; }
public string Name { get { return name; } }
public string Ticker { get { return ticker; } } }
I then inserted the code to load data into the DataList
private void Page_Load(object sender, System.EventArgs e) { if (!IsPostBack) { ArrayList values = new ArrayList(); values.Add(new PositionData("Microsoft", "Msft")); values.Add(new PositionData("Intel", "Intc")); values.Add(new PositionData("Dell", "Dell"));
DataList1.DataSource = values; DataList1.DataBind(); } } }
When I run the application into IE 6, All I saw was a blank screen with no DataList and nada. I try with DataGrid and everything works fine.
What have I done wrong?
Thank you in advance for all your help. | | |
Are these lines of code bind the DataList to its source?
DataList1.DataSource = values;
DataList1.DataBind();
According to the help files and everything I have
searched on the NET including MSDN indicates so. The code
posted in my first post was indeed coming from the sample
provided by Microsoft.
Thanh -----Original Message----- Did you actually bind the columns to the DataList?
Unlike the DataGrid, youmust visit the HTML section of the webform and bind the
datafield/propertyto each column in the list, whereas the datagrid
will "draw" the data basedon the datafield property set in the designer.
HTH,
Morgan
"Thanh" <an*******@discussions.microsoft.com> wrote in
messagenews:03****************************@phx.gbl... I created an ASP.NET project and dropped a DataList on the web form. I then wrote a simple class to return
data: namespace Playing { public class PositionData { private string name; private string ticker;
public PositionData(string name, string ticker) { this.name = name; this.ticker = ticker; }
public string Name { get { return name; } }
public string Ticker { get { return ticker; } } }
I then inserted the code to load data into the DataList
private void Page_Load(object sender,
System.EventArgs e) { if (!IsPostBack) { ArrayList values = new ArrayList(); values.Add(new PositionData
("Microsoft", "Msft")); values.Add(new PositionData("Intel", "Intc")); values.Add(new PositionData("Dell", "Dell"));
DataList1.DataSource = values; DataList1.DataBind(); } } }
When I run the application into IE 6, All I saw was a blank screen with no DataList and nada. I try with DataGrid and everything works fine.
What have I done wrong?
Thank you in advance for all your help.
. | | |
Yes, that will bind the data to the datalist, but you also need the
following added to your HTML ...
ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconbindingsqldatatodatalistcontro
l.htm
<body>
<%-- Open the DataList control and set it for two columns, to be
filled in horizontal order. --%>
<ASP:DataList id="MyDataList" RepeatColumns="2"
RepeatDirection="Horizontal" runat="server">
<ItemTemplate>
<div style="padding:15,15,15,15;font-size:10pt;font-family:Verdana">
<div style="font:12pt verdana;color:darkred">
<i><b><%# DataBinder.Eval(Container.DataItem, "title")%>
</i></b>
</div>
<br>
<b>Title ID: </b>
<%# DataBinder.Eval(Container.DataItem, "title_id") %><br>
<b>Category: </b>
<%# DataBinder.Eval(Container.DataItem, "type")%><br>
<b>Publisher ID: </b>
<%# DataBinder.Eval(Container.DataItem, "pub_id") %><br>
<b>Price: </b>
<%# DataBinder.Eval(Container.DataItem, "price", "{0:c}") %>
<p>
</div>
</ItemTemplate>
</ASP:DataList>
</body>
"Thanh" <an*******@discussions.microsoft.com> wrote in message
news:08****************************@phx.gbl... Are these lines of code bind the DataList to its source?
DataList1.DataSource = values; DataList1.DataBind();
According to the help files and everything I have searched on the NET including MSDN indicates so. The code posted in my first post was indeed coming from the sample provided by Microsoft.
Thanh
-----Original Message----- Did you actually bind the columns to the DataList? Unlike the DataGrid, youmust visit the HTML section of the webform and bind the datafield/propertyto each column in the list, whereas the datagrid will "draw" the data basedon the datafield property set in the designer.
HTH,
Morgan
"Thanh" <an*******@discussions.microsoft.com> wrote in messagenews:03****************************@phx.gbl... I created an ASP.NET project and dropped a DataList on the web form. I then wrote a simple class to return data: namespace Playing { public class PositionData { private string name; private string ticker;
public PositionData(string name, string ticker) { this.name = name; this.ticker = ticker; }
public string Name { get { return name; } }
public string Ticker { get { return ticker; } } }
I then inserted the code to load data into the DataList
private void Page_Load(object sender, System.EventArgs e) { if (!IsPostBack) { ArrayList values = new ArrayList(); values.Add(new PositionData ("Microsoft", "Msft")); values.Add(new PositionData("Intel", "Intc")); values.Add(new PositionData("Dell", "Dell"));
DataList1.DataSource = values; DataList1.DataBind(); } } }
When I run the application into IE 6, All I saw was a blank screen with no DataList and nada. I try with DataGrid and everything works fine.
What have I done wrong?
Thank you in advance for all your help.
. | | |
Thanks again Morgan for your help. I finally understand
what it really takes to populate the DataList and
Repeater web server controls with Data. In my opinion,
it's a very complicated and cumbersome process to have to
manually insert code into the HTML file to make it works.
It's not a user friendly way at all.
Thanh -----Original Message----- Yes, that will bind the data to the datalist, but you
also need thefollowing added to your HTML ... ms-
help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconbindingsqldatat
odatalistcontrol.htm
<body> <%-- Open the DataList control and set it for two
columns, to be filled in horizontal order. --%> <ASP:DataList id="MyDataList" RepeatColumns="2" RepeatDirection="Horizontal" runat="server"> <ItemTemplate> <div style="padding:15,15,15,15;font-
size:10pt;font-family:Verdana"> <div style="font:12pt verdana;color:darkred"> <i><b><%# DataBinder.Eval
(Container.DataItem, "title")%> </i></b> </div> <br> <b>Title ID: </b> <%# DataBinder.Eval
(Container.DataItem, "title_id") %><br> <b>Category: </b> <%# DataBinder.Eval(Container.DataItem, "type")% <br> <b>Publisher ID: </b> <%# DataBinder.Eval(Container.DataItem, "pub_id") % <br> <b>Price: </b> <%# DataBinder.Eval
(Container.DataItem, "price", "{0:c}") %> <p> </div> </ItemTemplate> </ASP:DataList> </body> | | |
Agreed there is more work involved, but you reduce the server-side (client
side, as well) overhead by not using the DataGrid control. I've gotten into
the habit of creating a single page with the DataList &/or Repeater control
and doing a copy-paste into new pages and making changes as needed. Takes
out the redundant work (for the most part...) involved with the controls
"Thanh" <an*******@discussions.microsoft.com> wrote in message
news:02****************************@phx.gbl... Thanks again Morgan for your help. I finally understand what it really takes to populate the DataList and Repeater web server controls with Data. In my opinion, it's a very complicated and cumbersome process to have to manually insert code into the HTML file to make it works. It's not a user friendly way at all.
Thanh
-----Original Message----- Yes, that will bind the data to the datalist, but you also need thefollowing added to your HTML ... ms- help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconbindingsqldatat odatalistcontrol.htm
<body> <%-- Open the DataList control and set it for two columns, to be filled in horizontal order. --%> <ASP:DataList id="MyDataList" RepeatColumns="2" RepeatDirection="Horizontal" runat="server"> <ItemTemplate> <div style="padding:15,15,15,15;font- size:10pt;font-family:Verdana"> <div style="font:12pt verdana;color:darkred"> <i><b><%# DataBinder.Eval (Container.DataItem, "title")%> </i></b> </div> <br> <b>Title ID: </b> <%# DataBinder.Eval (Container.DataItem, "title_id") %><br> <b>Category: </b> <%# DataBinder.Eval(Container.DataItem, "type")% <br> <b>Publisher ID: </b> <%# DataBinder.Eval(Container.DataItem, "pub_id") % <br> <b>Price: </b> <%# DataBinder.Eval (Container.DataItem, "price", "{0:c}") %> <p> </div> </ItemTemplate> </ASP:DataList> </body> | | |
Copy and paste is a good idea. By the time I gain more
knowledge about how DataList and Repeater work, I would
like to build an inherited web control to automate this
tedious process of populating the data.
Thanks again Morgan.
Merry Christmas and Happy New Year
Thanh -----Original Message----- Agreed there is more work involved, but you reduce the
server-side (clientside, as well) overhead by not using the DataGrid
control. I've gotten intothe habit of creating a single page with the DataList
&/or Repeater controland doing a copy-paste into new pages and making changes
as needed. Takesout the redundant work (for the most part...) involved
with the controls "Thanh" <an*******@discussions.microsoft.com> wrote in
messagenews:02****************************@phx.gbl... Thanks again Morgan for your help. I finally understand what it really takes to populate the DataList and Repeater web server controls with Data. In my opinion, it's a very complicated and cumbersome process to have
to manually insert code into the HTML file to make it
works. It's not a user friendly way at all.
Thanh
>-----Original Message----- >Yes, that will bind the data to the datalist, but you also need the >following added to your HTML ... >ms-
help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconbindingsqldatat odatalistcontro >l.htm > ><body> > <%-- Open the DataList control and set it for
two columns, to be > filled in horizontal order. --%> > <ASP:DataList id="MyDataList" RepeatColumns="2" > RepeatDirection="Horizontal" runat="server"> > <ItemTemplate> > <div style="padding:15,15,15,15;font- size:10pt;font-family:Verdana"> > <div style="font:12pt verdana;color:darkred"> > <i><b><%# DataBinder.Eval (Container.DataItem, "title")%> > </i></b> > </div> > <br> > <b>Title ID: </b> > <%# DataBinder.Eval (Container.DataItem, "title_id") %><br> > <b>Category: </b> > <%# DataBinder.Eval(Container.DataItem, "type")% ><br> > <b>Publisher ID: </b> > <%# DataBinder.Eval
(Container.DataItem, "pub_id") % ><br> > <b>Price: </b> > <%# DataBinder.Eval (Container.DataItem, "price", "{0:c}") %> > <p> > </div> > </ItemTemplate> > </ASP:DataList> ></body> >
. | | This discussion thread is closed Replies have been disabled for this discussion. Similar topics
1 post
views
Thread by pete K |
last post: by
|
4 posts
views
Thread by V. Jenks |
last post: by
|
10 posts
views
Thread by Bharat |
last post: by
|
4 posts
views
Thread by Patrick.O.Ige |
last post: by
|
6 posts
views
Thread by Paul |
last post: by
|
2 posts
views
Thread by Hans Merkl |
last post: by
|
3 posts
views
Thread by Mirek Endys |
last post: by
|
reply
views
Thread by Les Caudle |
last post: by
|
1 post
views
Thread by AJ |
last post: by
|
3 posts
views
Thread by Crazy Cat |
last post: by
| | | | | | | | | | |