2 u013202332 u013202332 于 2014.09.03 11:25 提问

datalist嵌套外层大类反复出现

我想要的效果是一门课程里面有很多微课,这门课程只出现一次,但是用了datalist后,该课程名称多次出现,有什么办法可以让课程名会出现一次吗?
前台代码:

<asp:DataList ID="dlFileType" RepeatColumns="1" runat="server" OnItemDataBound="dlFileType_ItemDataBound">
    <ItemTemplate>
        <table border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td width="22%" height="88" align="center" valign="top">
                    <img src='/images/users/Session["yonghuID"]/<%#DataBinder.Eval(Container.DataItem, "kcFengmianURL")%>'
                        width="80" height="80">
                </td>
                <td valign="top">
                    <table width="96%" border="0" cellpadding="0" cellspacing="0">
                        <tr width="100%">
                            <td colspan="2">
                                <%#DataBinder.Eval(Container.DataItem,"kcBiaoti") %>
                                <asp:Label ID="labFileType" runat="server" Visible="true" Text='<%# DataBinder.Eval(Container.DataItem,"kechengID")%>'></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td width="300">
                                <asp:DataList ID="dlFileList" runat="server" RepeatColumns="1" Width="100%">
                                    <ItemTemplate>
                                        <table cellspacing="1" cellpadding="1" width="100%" border="0">
                                            <tr>
                                                <td width="93%">
                                                    <font color="#393939">
                                                        <%-- <%#GetTitle((string)Convert.ToString(DataBinder.Eval(Container.DataItem, "cnvcTitle")),(string)Convert.ToString(DataBinder.Eval(Container.DataItem, "cnvcFileType")),(string)Convert.ToString(DataBinder.Eval(Container.DataItem, "cniBaseFileID")),(DateTime)DataBinder.Eval(Container.DataItem, "cndtPublishTime"))%>--%>
                                                        <%#DataBinder.Eval(Container.DataItem,"wkBiaoti") %>

                                                    </font>
                                                </td>
                                            </tr>
                                        </table>
                                    </ItemTemplate>
                                </asp:DataList>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </ItemTemplate>
</asp:DataList>

后台代码

       protected void Page_Load(object sender, EventArgs e)
    {
        binddata();
    }
    public void binddata()
    {

        string sqlSel = "select * from kechengXIAweikes ";          
        dlFileType.DataSource = operateData.getRows(sqlSel);
        dlFileType.DataBind();

    }

    protected void dlFileType_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            DataList dl = null;
            Label labTypeID = null;

            dl = (DataList)e.Item.FindControl("dlFileList");//在datalist中查找ID为dlfilelist的datalist,赋值给dl
            labTypeID = (Label)e.Item.FindControl("labFileType");//找到文件类型ID
            string typeID = labTypeID.Text.ToString();
            int iTypeID = Convert.ToInt32(typeID);
            string commandText = "select * from kechengXIAweikes";
            commandText = commandText + " Where kechengID=" + iTypeID;
            //------------
            string connString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = connString;
            conn.Open();
            SqlDataAdapter myCommand = new SqlDataAdapter(commandText, conn);
            DataSet ds = new DataSet();
            myCommand.Fill(ds, "kechengXIAweikes");
            conn.Close();
            //------------
            dl.DataSource = ds.Tables["kechengXIAweikes"]; ;
            dl.DataBind();
        }
    }

不知道描述的清不清楚,欢迎讨论。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!