开发者

Loading repeater when binding gridview in asp.net

I have a gridview like this:

<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>

开发者_运维技巧Now I am able to load successfull ShUrl and PostTitle. I am bringing titleId from the database also. Now as usual, a post might have several tag. So I want to load the repeater for the particular titleId.

On server side, I am simply binding the gv1 from the datable. Now how to load tags for the titleid:

I have already written the function on the server side, might help you all to guide me:

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


you have to use GridView RowDataBound Event for that

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜