Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > a problem about databindings.

Reply
Thread Tools

a problem about databindings.

 
 
Arvan
Guest
Posts: n/a
 
      05-22-2006
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?


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57