开发者

Getting data from different tables and databinding same repeater

I use Visual Studio 2008, C#, MS SQL Server 2005. I have 2 tables that called "record" and "Estatetypes". I have some records in "record" with their estatetype IDs开发者_开发百科. I have to list my records in a repeater. When i directly databind to repeater, i normally see record's estatetype IDs. But i want to get estatetype's name that is in "Estatetypes" table. I have a code like below. In this situation, "estatetype" feature must be list but i can only list estatetypeid. How can i get estatetype from "Estatetypes" and databind same repeater?

asp:Repeater ID="Estates" runat="server" OnItemDataBound="Estates_OnItemDataBound">

ItemTemplate>

asp:HiddenField ID="estate" runat="server" Value='<%#DataBinder.Eval(Container.DataItem,"RecID") %>' />

a href='EstateDetail.aspx?ID=<%#DataBinder.Eval(Container.DataItem,"recid") %>' ">

<%#DataBinder.Eval(Container.DataItem,"header") %>

a href='EstateDetail.aspx?ID=<%#DataBinder.Eval(Container.DataItem,"RecID") %>' >

<%#DataBinder.Eval(Container.DataItem,"estatetype") %>

/ItemTemplate>

/asp:repeater>


you have to apply join to both record table and estatype table like the following:

select Es.recid,Es.othercolumn, Es.estatetype, Es.otherColumn from Estatetypes Es,record rec where Es.ID = rec.EstatypeID

now you have one table that contain all the information from estatype and record now bind it to the gridview

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜