a problem about databindings.

A

Arvan

i create a project.it contains 1 aspx page,1 class page.
here is code in class page :
public static System.Web.UI.WebControls.DataGrid ArticleList;
public static void catalogClick(string catalogID)
{
if (catalogID != null)
{
string strSql = "SELECT dbo.Article.ArticleTitle,
dbo.Article.ArticleSummary, dbo.Article.ArticleContent, " +
"dbo.Article.ArticleID,
dbo.Article.ArticleDate, dbo.Article.ReadNums,dbo.Article.CommNums,
dbo.Article.Weather, dbo.Catalog.CatalogTitle, dbo.[User].Nickname " +
" FROM dbo.Article INNER JOIN dbo.Catalog ON
dbo.Article.CatalogID = dbo.Catalog.CatalogID INNER JOIN dbo.[User] ON
dbo.Article.UserID = dbo.[User].UserID " +
" where Catalog.CatalogID=" + catalogID +
"";
SqlDataSource sqlds = new SqlDataSource(strConn, strSql);
ArticleList.DataSource = sqlds;
ArticleList.DataBind();
}
}

default.aspx:
<asp:GridView ID="ArticleList" runat="server"
AutoGenerateColumns="False" BorderWidth="0px"
CellSpacing="1" ShowHeader="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="LogName" runat="server" Text="<%#
Eval("ArticleTitle") %>"></asp:Label>
Post Date:<asp:Label ID="LogDateLbl"
runat="server" Text="<%# Eval("ArticleDate") %>"></asp:Label><br />
<asp:Label ID="LogSum" runat="server" Text="<%#
Eval("ArticleSummary") %>"></asp:Label><br />
Category:<asp:Label ID="CataName" runat="server"
Text="<%# Eval("CatalogTitle") %>"></asp:Label>
| Author:<asp:Label ID="Usr" runat="server"
Text="<%# Eval("Nickname") %>"></asp:Label>
| Read:<asp:Label ID="ViewNumLbl" runat="server"
Text="<%# Eval("ReadNums") %>"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

but now i got errors,it said the format of server controls is incorrect.

how could i databind to a label control? i dont wanna add a sqldatasource
control to an aspx page.is there any else way to do it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top