2011-03-29 95 views
0

结合GridView的时候我有这样一个gridview:中继器加载在asp.net

<asp:GridView ID="gv1" AutoGenerateColumns="false" BorderWidth="0" runat="server" > 
    <Columns> 
    <asp:TemplateField> 
     <ItemTemplate> 
     <span style="font-family:Tahoma; font-size:14px;"> 
      <u> <a href="<%#DataBinder.Eval(Container.DataItem,"ShUrl")%>"> 
        <%#DataBinder.Eval(Container.DataItem,"PostTitle")%> 
      </a> 
      </u> 
     <br /> 
     </span> 

      <asp:Repeater ID="rp1" runat="server"> 
        <HeaderTemplate> 
          <ul>  
        </HeaderTemplate> 
        <ItemTemplate> 
          <li > 
          <a href="<%# Eval("TUrl")%>"> <%# Eval("TagName")%></a> 
          </li>  
        </ItemTemplate> 
        <FooterTemplate> 
          </ul>  
        </FooterTemplate> 
       </asp:Repeater> 
     </ItemTemplate> 
    </asp:TemplateField> 

    </Columns> 


</asp:GridView> 

现在我能够加载全成ShUrl和PostTitle。我也从数据库中带来了titleId。 和往常一样,一个帖子可能有几个标签。所以我想加载特定titleId的中继器。

在服务器端,我简单地绑定了来自datable的gv1。 现在如何加载标签的titleid:

我已经写在服务器端的功能,可以帮助大家来指导我:

private void LoadtagList(int titleId) 
    { 
    // calling DAL 
     rp1.DataSource = db.GetAllTagsForPost(titleId); 
     rp1.DataBind(); 
    } 

回答

1

,你必须使用的GridView RowDataBound事件为

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
    if(e.Row.RowType == DataControlRowType.DataRow)  
{ 

    System.Data.DataRowView dr = (System.Data.DataRowView)e.Row.DataItem; 
    if (Convert.ToString(dr["titleId"]) != "") 
    { 
     Repeater rp1 = (Repeater)e.Row.Findcontrol("rp1"); 
     rp1.DataSource = db.GetAllTagsForPost(titleId); 
     rp1.DataBind(); 
    } 

    } 
} 
+0

谢谢!它工作只是一点点更正rp1.DataSource = db.GetAllTagsForPost(Convert.ToInt32(dr [“titleId”]。ToString())); – Chris 2011-03-29 12:47:48

+0

@Chris,我刚刚复制了你的线条。祝你好运 :) – 2011-03-29 12:49:39