how can populate data in datalist view from the database

Posted by Umeshdwivedi under ASP.NET on 6/23/2011 | Points: 10 | Views : 11330 | Status : [Member] | Replies : 3
Dear All
i want to show data in datalist view
how can populate data in datalist to the programming
and my database in ms-access
any body help me

Latest Technology Trainer
And Part time software consultant



Responses

Posted by: Karthikanbarasan on: 6/23/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Here is full code for display data in datalist control:

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<script language="VB" runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
Dim myConnection As SqlConnection
Dim myCommand As SqlDataAdapter
' Create a connection to the "pubs" SQL database located on the
' local computer.
myConnection = New SqlConnection("server=localhost;" _
& "database=pubs;Trusted_Connection=Yes")
' Connect to the SQL database using a SQL SELECT query to get all
' the data from the "Titles" table.
myCommand = New SqlDataAdapter("SELECT * FROM Titles", myConnection)
' Create and fill a DataSet.
Dim ds As DataSet = new DataSet()
myCommand.Fill(ds)
' Bind MyDataList to the DataSet. MyDataList is the ID for
' the DataList control in the HTML section of the page.
MyDataList.DataSource = ds
MyDataList.DataBind()
End Sub
</script>

<%-- Display the data. -%>
<body>
<%-- Open the DataList control and set it for two columns, to be
filled in horizontal order. --%>
<ASPataList 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>
</ASPataList>
</body>
</html>

[C#]
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<script language="C#" runat="server">
void Page_Load(Object sender, EventArgs e)
{
// Create a connection to the "pubs" SQL database located on the
// local computer.
SqlConnection myConnection = new SqlConnection("server=localhost;" +
"database=pubs;Trusted_Connection=Yes");
// Connect to the SQL database using a SQL SELECT query to get all
// the data from the "Titles" table.
SqlDataAdapter myCommand = new SqlDataAdapter("SELECT * " +
" from Titles", myConnection);
// Create and fill a DataSet.
DataSet ds = new DataSet();
myCommand.Fill(ds);
// Bind MyDataList to the DataSet. MyDataList is the ID for
// the DataList control in the HTML section of the page.
MyDataList.DataSource = ds;
MyDataList.DataBind();
}
</script>

<%-- Display the data. -%>
<body>
<%-- Open the DataList control and set it for two columns, to be
filled in horizontal order. --%>
<ASPataList id="MyDataList" RepeatColumns="2"
RepeatDirection= "Horizontal" runat="server">
<%-- Create a DataList control template named "ItemTemplate". --%>
<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>
</ASPataList>
</body>
</html>

Thanks
Karthik
www.f5Debug.net

Umeshdwivedi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Umeshdwivedi on: 6/23/2011 [Member] Starter | Points: 25

Up
0
Down
thanks sir this code useful for me
thanks again

Latest Technology Trainer
And Part time software consultant

Umeshdwivedi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lakn2 on: 6/24/2011 [Member] Starter | Points: 25

Up
0
Down
try this

http://www.codeproject.com/KB/books/master_aspnet.aspx
http://www.aspnettutorials.com/tutorials/controls/DataList-Control-Edit-Update.aspx

Thanks&Regards
LakshmiNarayana Nalluri.

Umeshdwivedi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response