后台代码:string sqlstr = "select * from dbo.ROOMS INNER JOIN dbo.HOTELS ON dbo.ROOMS.HOTEL_CODE=dbo.HOTELS.HOTEL_CODE";前台代码: <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
                        AutoGenerateColumns="False" Font-Size="9pt" Width="95%"
                        onpageindexchanging="GridView1_PageIndexChanging"  PageSize="20"
                        style="margin-bottom: 6px" onrowdeleting="GridView1_RowDeleting" onrowdatabound="GridView1_RowDataBound1" >                        <HeaderStyle CssClass="DGTitleBG" Height="30" /> 
                           <Columns>
                            <asp:BoundField DataField="RM_ID" HeaderText="编  号">
                            <ControlStyle CssClass="DGTitleBG"></ControlStyle>
                            </asp:BoundField>
                            <asp:BoundField DataField="RM_CODE" HeaderText="房间编号">
                            <ControlStyle CssClass="DGTitleBG"></ControlStyle>
                            </asp:BoundField>
                            <asp:BoundField DataField="C_RMNAME" HeaderText="所属酒店">
                            <ControlStyle CssClass="DGTitleBG"></ControlStyle>
                            </asp:BoundField>
                            <asp:BoundField DataField="C_RMNAME" HeaderText="房间名称">
                            <ControlStyle CssClass="DGTitleBG"></ControlStyle>
                            </asp:BoundField>
                            <asp:BoundField DataField="VALUE_RATE" HeaderText="房间价格">
                            <ControlStyle CssClass="DGTitleBG">
                            </ControlStyle>
                            </asp:BoundField>
                            <asp:BoundField DataField="CAN_JIFENG" HeaderText="体验状态">
                            <ControlStyle CssClass="DGTitleBG">
                            </ControlStyle>
                            </asp:BoundField>
                            <asp:BoundField DataField="CAN_TRY" HeaderText="积分兑换">
                            <ControlStyle CssClass="DGTitleBG">
                            </ControlStyle>
                            </asp:BoundField>
                            <asp:CommandField HeaderText="操  作" ShowDeleteButton="True" ShowEditButton="True">
                            <ControlStyle Width="30px" Height="22px" CssClass="add_top"/>
                               <FooterStyle Height="30px" />
                            </asp:CommandField>
                        </Columns>
                      
                        <PagerStyle BorderColor="#FF0066" BorderWidth="100px" />
                    </asp:GridView>
高手帮帮忙....
在线等...

解决方案 »

  1.   

    string sqlstr = "select * from dbo.ROOMS INNER JOIN dbo.HOTELS ON dbo.ROOMS.HOTEL_CODE=dbo.HOTELS.HOTEL_CODE";后台查出来的数据放在dataset 或者 datatable 中,直接绑定到GridView1控件上,DataField指定字段名就行了
      

  2.   

    try{ 
    System.Data.SqlClient.SqlConnection conn = new SqlConnection("connstr");
                    conn.Open();
                    string sqlstr = "select * from dbo.ROOMS INNER JOIN dbo.HOTELS ON dbo.ROOMS.HOTEL_CODE=dbo.HOTELS.HOTEL_CODE";
                    SqlCommand cmd = new SqlCommand(sqlstr, conn);
                    SqlDataAdapter sAd = new SqlDataAdapter(sqlstr, conn);
                    DataSet ds = new DataSet();
                    sAd.Fill(ds);
                    this.GridView1.DataSource = ds;
    }
    catch(Exception e)
    {}