Click here to Skip to main content
15,912,578 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Hi
I would like to know how to do the following, I have a gridview with Image and binddata I want to place a repeater within the gridview but use a different datasource to populate the repeater using values returned by the Gridview datasource is this possible?

Regards
thanks in advance.
Posted

yep
use gridview RowDataBound

C#
protected void grv_RowDataBound(object sender, GridViewRowEventArgs e)
{
    switch (e.Row.RowState)
    {
        case DataControlRowState.Normal:
        case DataControlRowState.Alternate:
        case DataControlRowState.Edit:
            int idField = Convert.ToInt16(DataBinder.Eval(e.Row.DataItem, "idField"));
            Repeater rep= (Repeater )e.Row.FindControl("idRepeater");
            rep.DataSource = yourdatasource;
            rep.DataBind();
            break;
    }
}


i don't know if u need the bind always or only in edit mode.

use different cases to change that behaviour
 
Share this answer
 
Comments
mlingo209 28-Sep-12 11:21am    
I have data on that is on my Gridview I want to add a repeater that uses a value in a row as parameters in retrieving its own data and displaying as if its the gridview
nrgjack 28-Sep-12 11:49am    
once you have a specific data (in my example idField) you can retrieve with db call every kind of data you need.

you can make a method

privat DataTable GetDataForRepeater(int idField)
{
// your DAL logic
return yourData

}
ASP.NET
<asp:gridview id="GrdJobSht" runat="server" autogeneratecolumns="False" datasourceid="GetJobSheetDATA" xmlns:asp="#unknown">
 <columns>
  <asp:templatefield>
    <itemtemplate>  
      <table>
      <tr>
      <td rowspan="5" class="style4">
       <asp:image id="ProdImage" runat="server" height="152px" imageurl="<%# String.Format(ResolveUrl("ProductImage.ashx")+"{0}{1}","?id=",Eval("propImageId"))%>" style="margin-left: 0px" width="172px" bordercolor="Silver" borderstyle="Double" borderwidth="10pt" /> 
</td>                                              
</tr>
<tr>
<td class="style5">
<asp:label id="Label1" runat="server" text="Product ID:" font-italic="True">
 Font-Names="Times New Roman" Font-Size="Medium"></asp:label>
 </td>
 <td>
  <asp:label id="lblProdid" runat="server" text="<%# Eval("propProdId") %>"></asp:label>
 </td>
 </tr>
 <tr>
 <td class="style5">
 <asp:label id="Label2" runat="server" text="Description:" font-italic="True">
 Font-Names="Times New Roman" Font-Size="Medium"></asp:label>
 </td>
 <td>
   <asp:label id="lblDesc" runat="server" text="<%# Eval("propProdDesc") %>"></asp:label>
 </td>
 </tr>
 <tr>
 <td class="style5">
 <asp:label id="Label3" runat="server" text="Quantity:" font-italic="True">
 Font-Names="Times New Roman" Font-Size="Medium"></asp:label>
 </td>
 <td>
  <asp:label id="lblQty" runat="server" text="<%# Eval("propProdQty") %>"></asp:label>
 </td>
 </tr>
 <tr>
 <td class="style5">
 <asp:label id="Label4" runat="server" text="Colour:" font-italic="True">
 Font-Names="Times New Roman" Font-Size="Medium"></asp:label>
 </td>
 <td>
   <asp:label id="lblColor" runat="server" text="<%# Eval("propColour") %>"></asp:label>
 </td>
 </tr>
 <tr>
 <td class="style5">
  <asp:label id="Label5" runat="server" text="Def Design:" font-italic="True">
  Font-Names="Times New Roman" Font-Size="Medium"></asp:label>
  </td>
  <td>
   <asp:label id="lblDefDes" runat="server" text="<%# Eval("propDeflectionDesign") %>"></asp:label>
 </td>
 </tr></table>
 </itemtemplate>
</asp:templatefield>
</columns>
</asp:gridview>
<asp:objectdatasource id="GetJobSheetDATA" runat="server" selectmethod="GetJobSheet" typename="BusinessLogicLayer.QuoteProduct" xmlns:asp="#unknown">
  <selectparameters>
   <asp:controlparameter controlid="DDlQno" defaultvalue="129126" name="Qno" propertyname="SelectedValue" type="Int32" />
  </selectparameters>
  </asp:objectdatasource>


I want to add a repeater that will use "propProdId" and "DDlQno" as parameters in retrieving its own data
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900