<asp:GridView ID="DataGridView" runat="server" AutoGenerateColumns="false" 
                CellPadding="0" Font-Size="10pt" ForeColor="#333333" GridLines="Both" 
                Width="100%">
                <Columns>
                    <asp:BoundField DataField="LessionSessionName" HeaderStyle-Width="5%" 
                        HeaderText="节次" ItemStyle-BackColor="#004B97" ItemStyle-ForeColor="White" />
                    <asp:BoundField DataField="MachineRoomName" HeaderStyle-Width="4%" 
                        HeaderText="机房" ItemStyle-BackColor="#009393" ItemStyle-ForeColor="White" />
                    <asp:BoundField DataField="Week1" HeaderStyle-Width="15%" HeaderText="星期一" />
                    <asp:BoundField DataField="Week2" HeaderStyle-Width="15%" HeaderText="星期二" />
                    <asp:BoundField DataField="Week3" HeaderStyle-Width="15%" HeaderText="星期三" />
                    <asp:BoundField DataField="Week4" HeaderStyle-Width="15%" HeaderText="星期四" />
                    <asp:BoundField DataField="Week5" HeaderStyle-Width="15%" HeaderText="星期五" />
                    <asp:BoundField DataField="Week6" HeaderStyle-Width="8%" HeaderText="星期六" />
                    <asp:BoundField DataField="Week7" HeaderStyle-Width="8%" HeaderText="星期日" />
                </Columns>
                <RowStyle BackColor="#66B3FF" Height="30px" HorizontalAlign="Center" />
                <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" 
                    Height="40px" />
                <AlternatingRowStyle BackColor="#CECEFF" Height="30px" 
                    HorizontalAlign="Center" />
            </asp:GridView>
==============================================================================================================
绑定 DataGridViewBind数据
private void DataGridViewBind()
        {
            string weekId = this.ddlWeek.SelectedValue;
            this.DataGridView.DataSource = LessionTManager.GetWeekLessions(weekId);
            this.DataGridView.DataBind();
            bool aryBln = true;
            int aryInt = 0;
            for (int i = 1; i < this.DataGridView.Rows.Count; i++)
            {
                // 本行和上一行均为DataControlRowType.DataRow
                if (this.DataGridView.Rows[i].RowType == DataControlRowType.DataRow && this.DataGridView.Rows[i - 1].RowType == DataControlRowType.DataRow)
                {
                    // 相邻单元格的内容相同
                    if (this.DataGridView.Rows[i].Cells[0].Text == this.DataGridView.Rows[i - 1].Cells[0].Text)
                    {
                        if (aryBln)
                            aryInt = i - 1;
                        if (this.DataGridView.Rows[aryInt].Cells[0].RowSpan == 0)
                            this.DataGridView.Rows[aryInt].Cells[0].RowSpan = 1;
                        this.DataGridView.Rows[aryInt].Cells[0].RowSpan++;
                        this.DataGridView.Rows[i].Cells[0].Visible = false;
                        aryBln = false;
                    }
                    else
                    {
                        aryBln = true;
                    }                }
            }
=========================================================================================================
数据库执行存储过程返回数据
public static DataSet GetWeekLessions(string weekId)
        {
            SqlParameter[] parameters = new System.Data.SqlClient.SqlParameter[1];
            parameters[0] = new SqlParameter("@WeekId", weekId);
            DataSet ds = DBHelper.ExecuteDataSet(CommandType.StoredProcedure, "SP_WeekLession", parameters);
            return ds;
        }=========================================================================================================
SP_WeekLession就是这个了,郁闷两层拿过来改三层,数据库存储过程没拿,数据库菜鸟求写个下面这个是数据库字段 
============================================================================
-----课表-----
create table LessionT
(
LessionId char(5) not null primary key,
WeekId char(2) not null references WeekT(WeekId),
WDay  char(1) not null,
LessionSessionId char(1) not null references LessionSessionT(LessionSessionId),
BeginTime smalldatetime not null,
EndTime smalldatetime not null,
ClassId char(6)  references ClassT(ClassId),
ClassId2 char(6) references ClassT(ClassId),
ClassName nvarchar(20),
ClassName2 nvarchar(20),
MachineRoomName varchar(20) not null,
CourseName varchar(20) ,
TeacherName varchar(20)
)

解决方案 »

  1.   

    if exists(select *from sysobjects where name='SP_WeekLession')
    drop proc SP_WeekLession
    go
    create proc SP_WeekLession
    @WeekId varchar(20)
    as
    select *from LessionT where WeekId=@WeekId
    go试一下行不行
      

  2.   


    Week1 上面的数据源是这个,要怎么才存储过程中把数据集中到这个Week1上面去,要显示的是课程名CourseName ,班级名ClassId ,教师名TeacherName