a problem about databindings.

Discussion in 'ASP .Net Datagrid Control' started by Arvan, May 22, 2006.

  1. Arvan

    Arvan Guest

    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?
     
    Arvan, May 22, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Aaron Ackerman
    Replies:
    1
    Views:
    5,293
    Aaron Ackerman
    Feb 16, 2004
  2. whaletyr

    Databindings question

    whaletyr, May 19, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    399
    whaletyr
    May 19, 2004
  3. Steve
    Replies:
    4
    Views:
    455
    Steve
    Jan 27, 2006
  4. =?Utf-8?B?UFc=?=
    Replies:
    0
    Views:
    983
    =?Utf-8?B?UFc=?=
    Apr 24, 2006
  5. James
    Replies:
    1
    Views:
    345
    James
    Nov 24, 2006
Loading...

Share This Page