我做了一个论坛其中一张是主题贴表A,有字段(noteid,title,content,TTime,usename,)另一张是回贴表B(renoteid,noteid,content,username,TTime,)两表通过noteid联系我想在页面中
第一楼显示主题贴的内容,右边有一个"编辑'按钮(vs2003.net自动生成的)每行少添加一个编辑按钮,因此需要用到datakeyfield,(e.item.itemindex作编辑或删除用)第二楼显示回贴的内容,右边同样有一个“编辑”按钮(也是VS2003。NET自动生成的)怎样将两张表中不同列(A.conten和B.content)的内容显示在一个DataGrid的同一列中?注:究竟用哪一个表的哪一个字段作为DataGrid的datakeyfield好呢(注:在同一DataGrid中)?在数据绑定列的时候,怎么绑定呢?对以上内容如若还有不清楚,下面是我程序包的地址,具体页面在detail1.aspx(注意不是detail.asp),注:不用从头运行起,因为我的程序可能有很多错误,只要detail1.aspx解决即可,
http://bbs.dvbbs.net/dispbbs.asp?boardid=1&id=1276813&star=1#1276813

解决方案 »

  1.   

    高手能说一下,具体怎样做吗?或者,把它做出来,再传到我上面的那个网址中。我没用VS2003.NET做过DataGrid嵌套DataGrid?
      

  2.   

    DataGrid嵌套DataGrid例子:
    <asp:datagrid id="grid" runat="server" PageSize="5" ShowHeader="False" AllowPaging="True" AutoGenerateColumns="False"
    Width="100%">
    <Columns>
    <asp:TemplateColumn>
    <ItemTemplate>
    <TABLE cellSpacing="0" cellPadding="0" width="100%" border="0">
    <TR height="30">
    <TD bgColor='<%=Application[Session["Style"].ToString()+"xtable_titlebgcolor"]%>'>
    <STRONG><B>素质岗位:
    <%# DataBinder.Eval(Container.DataItem, "StationName") %>
    </B></STRONG>
    </TD>
    </TR>
    <TR>
    <TD align="right">
    <asp:DataGrid id=dgDetail runat="server" AutoGenerateColumns="False" DataSource='<%# ((System.Data.DataRowView)Container.DataItem).CreateChildView("tableRelation") %>' DataKeyField="CurriculaID" BorderColor="#336666" BorderWidth="1px" CellPadding="5" CellSpacing="0" GridLines="Horizontal" Width="100%" Font-Size="Smaller">
    <Columns>
    <asp:BoundColumn Visible="False" DataField="CurriculaID" ReadOnly="True"></asp:BoundColumn>
    <asp:TemplateColumn HeaderText="考试课程">
    <HeaderStyle Width="100px"></HeaderStyle>
    <ItemTemplate>
    <%# DataBinder.Eval(Container.DataItem, "CurriculaName") %>
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:BoundColumn DataField="StartTime" ReadOnly="True" HeaderText="预设开考时间" HeaderStyle-Width="75px"></asp:BoundColumn>
    <asp:BoundColumn DataField="EndTime" ReadOnly="True" HeaderText="预设结束时间" HeaderStyle-Width="75px"></asp:BoundColumn>
    </Columns>
    <PagerStyle HorizontalAlign="Center" ForeColor="White" BackColor="#336666" Mode="NumericPages"></PagerStyle>
    </asp:DataGrid>
    </TD>
    </TR>
    </TABLE>
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:BoundColumn Visible="False" DataField="ID" ReadOnly="True"></asp:BoundColumn>
    <asp:BoundColumn HeaderText="考试课程"></asp:BoundColumn>
    </Columns>
    <PagerStyle Visible="False"></PagerStyle>
    </asp:datagrid>
    DataSet myDataSet=new DataSet();
    BLL.Station bll=new BLL.Station();
    myDataSet=bll.GetList(strWhere.Replace("StationID","ID")); DataSet ds = new DataSet();
    V_ExamPlan_Curricula bllV=new V_ExamPlan_Curricula();
    strWhere=strWhere.Replace("DelSign=0","'1'='1'");
    if(strWhere!="")
    {
    strWhere=strWhere+" AND PlanID='"+lblID.Text+"'";
    }
    else
    {
    strWhere="PlanID='"+lblID.Text+"'";
    }
    ds=bllV.GetList(strWhere);
    DataTable myTable=ds.Tables[0].Copy();
    myTable.TableName="C";
    myDataSet.Tables.Add(myTable);
    try
    {
    //设定表名字
    myDataSet.Tables[0].TableName = "Station";
    myDataSet.Tables[1].TableName = "V_Station_Curricula";
    DataColumn Parent = myDataSet.Tables["Station"].Columns["ID"];
    DataColumn Child  = myDataSet.Tables["V_Station_Curricula"].Columns["StationID"];
    DataRelation tableRelation = new DataRelation("tableRelation", Parent, Child, false);
    myDataSet.Relations.Add(tableRelation);
    }
    catch(Exception error)
    {
    Response.Write(error.ToString());
    } grid.DataSource = myDataSet.Tables["Station"].DefaultView;
    grid.DataBind();
      

  3.   

    向DataSet新加一列:
    bfNewsSort = new ech_NewsSortBF();         DataTable dt = new DataTable();
    dt = dsNewsInfo.NewsInfo.Copy();
    dt.Columns.Add("TypeName",typeof(string)); for (int i = 0;i < dt.Rows.Count;i ++)
    {
    dt.Rows[i]["TypeName"] = bfNewsSort.GetSortNameBySortID((int)dt.Rows[i]["NewsSortID"]);
    } this.drgNews.DataSource = dt;
    this.drgNews.DataBind();