show in a repeater every 2 items in one line

I have a site in ASP.NET 2.0 with C#.
I have a repeater in the site that is bound to a datatable,
I have to show every 2 items in one line one next to the other and then
the next 2 items  and so on. How shall I do that?
thankyou
anat
ANAT2403Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
SteveH_UKConnect With a Mentor Commented:
The easiest solution is to use an ItemTemplate to represent the first item in each row and an AlternatingItemTemplate to represent the second item in each row.  If you were doing a simple table layout, it might look like:

<asp:Repeater id="r1" runat="server">
<HeaderTemplate><table><tbody></HeaderTemplate>
<ItemTemplate><tr><td><asp:Literal runat="server" Text='<%# Container.DataItem.ToString() %>'/></td></ItemTemplate>
<AlternatingItemTemplate><td><asp:Literal runat="server" Text='<%# Container.DataItem.ToString() %>'/></td></tr></AlternatingItemTemplate>
<FooterTemplate></tbody></table></FooterTemplate>
</asp:Repeater>
0
 
xPert_UmerCommented:
user to itemtemplate for each line
0
 
ANAT2403Author Commented:
Hi SteveH,
It seems good and I am just checking it. I have just one more small question:
Supposoe  I have different lines to show according to cases in the repeater. Is it O.K. to use some panels and show the appropriate one and hide the rest or is there another  possibility.
thankyou
anat
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
SteveH_UKCommented:
Yes, what you suggest is fine.  Of course your logic might get complicated, but using panels to show or hide sections is absolutely fine.  I do exactly the same in nested repeaters using data-bound expressions.
0
 
ANAT2403Author Commented:
Hi SteveH,
thanks for the quick answer but you know, I do have a problem here:
I have 3 cases of lines that I prepare 3 panels for them and in one panel I have to show
2 lines one next to the other with the alternateitemtemlate.  I decalred the itemtemplate outside the
panels. now I have difficulties where to enter the alternateitemtemplate?
Can you help?
Thankyou
0
 
SteveH_UKCommented:
Perhaps you could provide more detail, or your current code.  It is a little difficult to visualize exactly what you are trying to do.  I understand how you've got stuck (changes between ItemTemplate and AlternatingItemTemplate) but it is difficult to give a precise solution.

In these cases, I'd include the whole logic in a single ItemTemplate, but use conditional data bound expressions (using class member functions in the control or page) on HTML controls to specify whether or not to display different elements.  It means you have to code for the alternating pattern directly, but it gives you complete flexibility on the rendering.  Remember that you can use runat="server" on HTML controls (such as TABLE, TR, TH, TD and DIV), as well as the ASP.NET ones.
0
 
ANAT2403Author Commented:
Hi SteveH
Suppose I use the HTML controls as you suggests , Is this mean that it will be instead of the panels?
Shall I still use the repeater?
Thankyou
Anat
0
 
SteveH_UKCommented:
It can be instead of the panels, or as well as.  It just means you can choose whether or not to show a TD element, for example, on the basis of your data.  You should use a repeater if you have repeating data items, but how they display is entirely up to you.

Why don't you post a bit more of what you are trying to do (and have already done), so we can work with that?
0
 
ANAT2403Author Commented:
Hi SteveH
I will be delighted to send the code. O.K. let me explain what I am sending:
again I am suppose to get a format of 4 lines: the first header line at the top then 2  item  lines one next to the other but in what I am sending it is still one after the other and this is my problem  and a forth line  as a footer. this group of 4 lines is suppose to repeat.
I already prepared a datatable that include this format and I will send also the code behind that deal with the 3 panels.
first I send the design of the repeater that include now 3 panels:
and then the code behind.
Maybe I have to change the preparing of the the datatable: Lets think together:
now for each group of 2 items I add 2 lines of header and footer in the datatable.
may be I should leave only the item  lines  in the datatable and deal with the header and footer of the group in the
design code.
I hope I succeeded to explain what I mean.
Thanks in advance,
Anat

  the design code
  -----------------
           <!-- start main content middle-->
                                                 
                  <!-- ITEM -->
                   <table cellspacing="0" cellpadding="4" class="product_table" >
                    <tr>
                   <td>
                    <asp:Repeater runat="server" ID="RPModels" OnItemDataBound="RPModels_ItemDataBound"  >
                   <ItemTemplate> 
                   <!-- panel 1 for showing a the category label --> 
                    
                   <asp:Panel runat="server" ID="pnlCatTop" Visible="false">
                       <table><tr class="blue_tr"><td class="white_link">
                        <asp:HyperLink ID ="HLCatTop" runat="server" Font-Underline="false"><%# Eval("Cat_Name")%></asp:HyperLink>
                       </td ></tr></table>
                   </asp:Panel>
                  
                    <!-- panel  2  for showing a regular ITEM --> 
                   
                    <asp:Panel  ID = "pnlmodel" runat="server">               
                     <table ><tr>
                        <td class="prod_img">
                          <asp:HyperLink ID ="HLimgModel" runat="server" >  
                            <asp:Image ID="ImgModel" runat="server"  /><br />
                             <%# Eval("Stores")%> items found </asp:HyperLink>
                         </td>
                        <td><h3>
                          <asp:HyperLink ID ="HLModelName" runat="server"  ><%# Eval("Model_Name")%></asp:HyperLink>
                        </h3>
                          <div style="padding:3px; color:#40558b; font-weight:bold;" >
                        <asp:Label ID="lblMinPrice" runat="server"  Text='<%# Eval("MinPrice")%>'> </asp:Label>
                        &nbsp;-&nbsp;
                        <asp:Label ID="lblMaxPrice" runat="server"  Text='<%# Eval("[MaxPrice]")%>'> </asp:Label>
                      </div>
                      <div >
                        <asp:Button ID="btnComparep" runat="server" Text="Compare Prices"  UseSubmitBehavior="False" />
                      </div></td>
                   </tr>            
                  </table>
                   </asp:Panel>  
 
                <!--  panel 3 for showing the More link -->
                    <asp:Panel  ID = "pnlMore" runat="server" Visible="false">  
                     <table style="width:100%"><tr>
                        <td  style="text-align:right;background-image:url(images/search_cat_bg.png)">              
                          <asp:HyperLink ID ="HLModelNameM" runat="server" Font-Underline="true">See all <%# Eval("Cat_Name")%>&gt;&gt;
                            </asp:HyperLink>
                        </td>
                   </tr>
                   <tr>
                       <td  style="height: 1px; background-color:#cccccc">
                       </td>
                   </tr>
                   <tr>
                       <td  style="height:5px;">
                       </td>
                   </tr>
                   
                    </table>  
                   </asp:Panel>  
                    </ItemTemplate>
                   </asp:Repeater>             
                   </td></tr>
                  </table>
   
                
                  <!-- / ITEM -->
 the code behind
-----------------
  protected void RPModels_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        string HPstrProductURL;
        try
        {
 
            if (e.Item.ItemType == ListItemType.AlternatingItem ||
                e.Item.ItemType == ListItemType.Item)
            {
                Panel pnlmore = (Panel)e.Item.FindControl("pnlMore");
                Panel pnlmodel = (Panel)e.Item.FindControl("pnlmodel");
                Panel pnlcat = (Panel)e.Item.FindControl("pnlCatTop");
 
                string modelId = ((DataRowView)(e.Item.DataItem))["ModelID"].ToString();
                string Model_Name = ((DataRowView)(e.Item.DataItem))["Model_Name"].ToString();
 
                if (Model_Name == Declarations.Str_Cat_Top)
                {  // dealing with case of category top name
                    pnlmore.Visible = false;
                    pnlmodel.Visible = false;
                    pnlcat.Visible = true;
 
                    string Cat_name_s = ((DataRowView)(e.Item.DataItem))["Cat_Name"].ToString();
                    HPstrProductURL = "~/models.aspx?cat=" + System.Web.HttpUtility.UrlEncode(Cat_name_s);
                    HyperLink Hpcattop = (HyperLink)e.Item.FindControl("HLCatTop");
                    Hpcattop.NavigateUrl = HPstrProductURL;
 
                }
                else
                if (Model_Name == Declarations.Str_More_Top) 
                {  // dealing with case of nore link
                    pnlmore.Visible = true;
                    pnlmodel.Visible = false;
                    pnlcat.Visible = false;
 
                    string Cat_name_s = ((DataRowView)(e.Item.DataItem))["Cat_Name"].ToString();
 
                    HPstrProductURL = "~/models.aspx?cat=" + System.Web.HttpUtility.UrlEncode(Cat_name_s);
                    HyperLink Hp1 = (HyperLink)e.Item.FindControl("HLModelNameM");
                    Hp1.NavigateUrl = HPstrProductURL;
                }
                else
                {  // dealing of case of regular nodel
                    pnlmore.Visible = false;
                    pnlmodel.Visible = true;
                    pnlcat.Visible = false;
 
                    HPstrProductURL = "~/product.aspx?model_name=" + Model_Name;
 
                    HyperLink Hp1 = (HyperLink)e.Item.FindControl("HLModelName");
                    Hp1.NavigateUrl = HPstrProductURL;
 
                    HyperLink Hp2 = (HyperLink)e.Item.FindControl("HLimgModel");
                    Hp2.NavigateUrl = HPstrProductURL;
 
                    Button btncomp = (Button)e.Item.FindControl("btnComparep");
                    btncomp.PostBackUrl = HPstrProductURL;
 
                    Label lblMin = (Label)e.Item.FindControl("lblMinPrice");
                    string minpStr = String.Format("{0:C}", decimal.Parse(lblMin.Text));
                    lblMin.Text = minpStr.ToString();
 
                    Label lblMax = (Label)e.Item.FindControl("lblMaxPrice");
                    string maxpStr = String.Format("{0:C}", decimal.Parse(lblMax.Text));
                    lblMax.Text = maxpStr.ToString();
 
                    Image i1 = (Image)e.Item.FindControl("ImgModel");
                    string strURL = ServerAddr + "vg_paint?s=main&w=80&bg=bg1&h=60&q=85&f=models/" + modelId + ".jpg";
 
 
                    i1.ImageUrl = strURL;
                    i1.AlternateText = Model_Name;
                }
 
            }
        }
        catch (Exception ex)
        {
            using (ErrorLog Err = new ErrorLog(ex, ""))
            {
                Err.logErrorString();
            }
        }
    }                 

Open in new window

0
 
SteveH_UKCommented:
OK.  You've made your life quite difficult by the way you've constructed your data table and also the markup.

You should start by considering how the final HTML should look, for example your code currently renders as shown in the snippet.

Now, you probably don't want these embedded tables nor do you want the divs (created by the asp:Panel controls).  You can use asp:Placeholder to insert controls without a containing div, but for the rest you need to work out how it should display.  Then it is relatively easy to convert it to a Repeater.

Each PlaceHolder control within the ItemTemplate should present only the required markup to make the item complete.  It should not try to be well formed since you want the alternative renderings to work together.  In a simple case, you would have something like this:

<asp:Repeater ...>
  <HeaderTemplate><table><tbody></HeaderTemplate>
  <ItemTemplate>
    <asp:PlaceHolder id="oddItems"><tr><td><%# Eval("ItemText") %></td></asp:PlaceHolder>
    <asp:PlaceHolder id="evenItems"><td><%# Eval("ItemText") %></td></tr></asp:PlaceHolder>
  </ItemTemplate>
  <FooterTemplate></tbody></table></FooterTemplate>
</asp:Repeater>

If you can provide the actual HTML rendering you'd like to achieve, I'll help further.
    <table cellspacing="0" cellpadding="4" class="product_table">
        <tr>
            <td>
                <!-- panel 1 for showing a the category label -->
                <div runat="server" id="pnlCatTop" visible="false">
                    <table>
                        <tr class="blue_tr">
                            <td class="white_link">
                                <a id="HLCatTop" runat="server" font-underline="false">Cat_Name</a>
                            </td>
                        </tr>
                    </table>
                </div>
                <!-- panel  2  for showing a regular ITEM -->
                <div id="pnlmodel" runat="server">
                    <table>
                        <tr>
                            <td class="prod_img">
                                <a id="HLimgModel" runat="server">
                                    <img id="ImgModel" runat="server" /><br />
                                    <%# Eval("Stores")%>
                                    items found </a>
                            </td>
                            <td>
                                <h3>
                                    <a id="HLModelName" runat="server">
                                        <%# Eval("Model_Name")%>
                                    </a>
                                </h3>
                                <div style="padding: 3px; color: #40558b; font-weight: bold;">
                                    <label id="lblMinPrice" runat="server" text='<%# Eval("MinPrice")%>'>
                                    </label>
                                    &nbsp;-&nbsp;
                                    <label id="lblMaxPrice" runat="server" text='<%# Eval("[MaxPrice]")%>'>
                                    </label>
                                </div>
                                <div>
                                    <asp:button id="btnComparep" runat="server" text="Compare Prices" usesubmitbehavior="False" />
                                </div>
                            </td>
                        </tr>
                    </table>
                </div>
                <!--  panel 3 for showing the More link -->
                <div id="pnlMore" runat="server" visible="false">
                    <table style="width: 100%">
                        <tr>
                            <td style="text-align: right; background-image: url(images/search_cat_bg.png)">
                                <a id="HLModelNameM" runat="server" font-underline="true">See all
                                    <%# Eval("Cat_Name")%>
                                    &gt;&gt; </a>
                            </td>
                        </tr>
                        <tr>
                            <td style="height: 1px; background-color: #cccccc">
                            </td>
                        </tr>
                        <tr>
                            <td style="height: 5px;">
                            </td>
                        </tr>
                    </table>
                </div>
            </td>
        </tr>
    </table>

Open in new window

0
 
ANAT2403Author Commented:
Hi SteveH
Well I am really in a mess. I hope you will help me to get out of it.
O.K. Now I am dealling it from different direction:
I prepared my datatable to include only the items and I have a repeater with itemtemplat and alternateitemtemplate and I have 2 items in a line.
The problem now is to enter a header line and a footer line before and after thes 2 items line.
Do you think I shall consider using another repeater? so that the inner repeater will include also a header and a footer?
I am waiting to hear from you
Thankyou

Anat


the design code
                    <asp:Repeater runat="server" ID="RPModels" OnItemDataBound="RPModels_ItemDataBound"  >
 
              <ItemTemplate> 
               <tr><td>     
                   
                     <table ><tr >
                        <td class="prod_img" >
                          <asp:HyperLink ID ="HLimgModel" runat="server" >  
                            <asp:Image ID="ImgModel" runat="server"  /><br />
                             <%# Eval("Stores")%> items found </asp:HyperLink>
                         </td>
                        <td><h3>
                          <asp:HyperLink ID ="HLModelName" runat="server"  ><%# Eval("Model_Name")%></asp:HyperLink>
                        </h3>
                          <div style="padding:3px; color:#40558b; font-weight:bold;" >
                        <asp:Label ID="lblMinPrice" runat="server"  Text='<%# Eval("MinPrice")%>'> </asp:Label>
                        &nbsp;-&nbsp;
                        <asp:Label ID="lblMaxPrice" runat="server"  Text='<%# Eval("[MaxPrice]")%>'> </asp:Label>
                      </div>
                      <div >
                        <asp:Button ID="btnComparep" runat="server" Text="Compare Prices"  UseSubmitBehavior="False" />
                      </div></td>
                   </tr>            
                  </table>
 
                   
                   </td>
              </ItemTemplate>
                    
              <AlternatingItemTemplate>
              <td>
                       <table ><tr style="text-align:right;">
                        <td class="prod_img">
                          <asp:HyperLink ID ="HLimgModel" runat="server" >  
                            <asp:Image ID="ImgModel" runat="server"  /><br />
                             <%# Eval("Stores")%> items found </asp:HyperLink>
                         </td>
                        <td><h3>
                          <asp:HyperLink ID ="HLModelName" runat="server"  ><%# Eval("Model_Name")%></asp:HyperLink>
                        </h3>
                          <div style="padding:3px; color:#40558b; font-weight:bold;" >
                        <asp:Label ID="lblMinPrice" runat="server"  Text='<%# Eval("MinPrice")%>'> </asp:Label>
                        &nbsp;-&nbsp;
                        <asp:Label ID="lblMaxPrice" runat="server"  Text='<%# Eval("[MaxPrice]")%>'> </asp:Label>
                      </div>
                      <div >
                        <asp:Button ID="btnComparep" runat="server" Text="Compare Prices"  UseSubmitBehavior="False" />
                      </div></td>
                   </tr>            
                  </table>
                   </td></tr> 
              </AlternatingItemTemplate>
 
                   </asp:Repeater>             
the code behind
---------------
  protected void RPModels_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        string HPstrProductURL;
        try
        {
 
            if (e.Item.ItemType == ListItemType.AlternatingItem ||
                e.Item.ItemType == ListItemType.Item)
            {
                numitems++;
                string modelId = ((DataRowView)(e.Item.DataItem))["ModelID"].ToString();
                string Model_Name = ((DataRowView)(e.Item.DataItem))["Model_Name"].ToString();
 
 
                HPstrProductURL = "~/product.aspx?model_name=" + Model_Name;
 
                HyperLink Hp1 = (HyperLink)e.Item.FindControl("HLModelName");
                Hp1.NavigateUrl = HPstrProductURL;
 
                HyperLink Hp2 = (HyperLink)e.Item.FindControl("HLimgModel");
                Hp2.NavigateUrl = HPstrProductURL;
 
                Button btncomp = (Button)e.Item.FindControl("btnComparep");
                btncomp.PostBackUrl = HPstrProductURL;
 
                Label lblMin = (Label)e.Item.FindControl("lblMinPrice");
                string minpStr = String.Format("{0:C}", decimal.Parse(lblMin.Text));
                lblMin.Text = minpStr.ToString();
 
                Label lblMax = (Label)e.Item.FindControl("lblMaxPrice");
                string maxpStr = String.Format("{0:C}", decimal.Parse(lblMax.Text));
                lblMax.Text = maxpStr.ToString();
 
                Image i1 = (Image)e.Item.FindControl("ImgModel");
                string strURL = ServerAddr + "vg_paint?s=main&w=80&bg=bg1&h=60&q=85&f=models/" + modelId + ".jpg";
 
 
                i1.ImageUrl = strURL;
                i1.AlternateText = Model_Name;
 
            }
        }
        catch (Exception ex)
        {
            using (ErrorLog Err = new ErrorLog(ex, ""))
            {
                Err.logErrorString();
            }
        }
    }

Open in new window

0
 
ANAT2403Author Commented:
Hi SteveH,
I did it ! it worked!
what I did is the following: I went back to my initial version where I prepared in the datatable 4 lines for 2 items including the header and footer. I had 3 panels and I changed the second panel to be 2 panels but in one table, and in the code behind I checked where to send and it worked.
I am not sure if this is the best code but it worked.
Anyhow there are some things I would like to advise with you.
Can I write to you?
anyhow you helped me a lot.
Anat
In the design
------------------
                <!-- ITEM -->
                   <table cellspacing="0" cellpadding="4" class="product_table" >
                    <tr>
                   <td>
                    <asp:Repeater runat="server" ID="RPModels" OnItemDataBound="RPModels_ItemDataBound"  >
                   <ItemTemplate> 
                   <!-- panel 1 for showing a the category label --> 
                    
                   <asp:Panel runat="server" ID="pnlCatTop" Visible="false">
                       <table><tr class="blue_tr"><td class="white_link">
                        <asp:HyperLink ID ="HLCatTop" runat="server" Font-Underline="false"><%# Eval("Cat_Name")%></asp:HyperLink>
                       </td ></tr></table>
                   </asp:Panel>
                  
                    <!-- panel  21  for showing a regular ITEM  in the left side--> 
                   
                    <asp:Panel  ID = "pnlmodel" runat="server">               
                     <table style="width:100%"><tr>
                        <td class="prod_img">
                          <asp:HyperLink ID ="HLimgModel" runat="server" >  
                            <asp:Image ID="ImgModel" runat="server"  /><br />
                             <%# Eval("Stores")%> items found </asp:HyperLink>
                         </td>
                        <td><h3>
                          <asp:HyperLink ID ="HLModelName" runat="server"  ><%# Eval("Model_Name")%></asp:HyperLink>
                        </h3>
                          <div style="padding:3px; color:#40558b; font-weight:bold;" >
                        <asp:Label ID="lblMinPrice" runat="server"  Text='<%# Eval("MinPrice")%>'> </asp:Label>
                        &nbsp;-&nbsp;
                        <asp:Label ID="lblMaxPrice" runat="server"  Text='<%# Eval("[MaxPrice]")%>'> </asp:Label>
                      </div>
                      <div >
                        <asp:Button ID="btnComparep" runat="server" Text="Compare Prices"  UseSubmitBehavior="False" />
                      </div></td>
                    </asp:Panel>
 
                    <!-- panel  22  for showing a regular ITEM in the right side --> 
                    
                    <asp:Panel  ID = "pnlmodel_r" runat="server">               
 
                      <td class="prod_img">
                          <asp:HyperLink ID ="HLimgModel_r" runat="server" >  
                            <asp:Image ID="ImgModel_r" runat="server"  /><br />
                             <%# Eval("Stores")%> items found </asp:HyperLink>
                         </td>
                        <td><h3>
                          <asp:HyperLink ID ="HLModelName_r" runat="server"  ><%# Eval("Model_Name")%></asp:HyperLink>
                        </h3>
                          <div style="padding:3px; color:#40558b; font-weight:bold;" >
                        <asp:Label ID="lblMinPrice_r" runat="server"  Text='<%# Eval("MinPrice")%>'> </asp:Label>
                        &nbsp;-&nbsp;
                        <asp:Label ID="lblMaxPrice_r" runat="server"  Text='<%# Eval("[MaxPrice]")%>'> </asp:Label>
                      </div>
                      <div >
                        <asp:Button ID="btnComparep_r" runat="server" Text="Compare Prices"  UseSubmitBehavior="False" />
                      </div></td>
  
                   </tr>            
                  </table>
                   </asp:Panel>  
 
                <!--  panel 3 for showing the More link -->
                    <asp:Panel  ID = "pnlMore" runat="server" Visible="false">  
                     <table style="width:100%"><tr>
                        <td  style="text-align:right;background-image:url(images/search_cat_bg.png)">              
                          <asp:HyperLink ID ="HLModelNameM" runat="server" Font-Underline="true">See all <%# Eval("Cat_Name")%>&gt;&gt;
                            </asp:HyperLink>
                        </td>
                   </tr>
                   <tr>
                       <td  style="height: 1px; background-color:#cccccc">
                       </td>
                   </tr>
                   <tr>
                       <td  style="height:5px;">
                       </td>
                   </tr>
                   
                    </table>  
                   </asp:Panel>  
                    </ItemTemplate>
                   </asp:Repeater>             
                   </td></tr>
                  </table>
   
                
                  <!-- / ITEM -->
                  
 
 </td>
              </tr>
            </table>
the code behind
-----------------
   protected void RPModels_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        string HPstrProductURL;
        string strURL;
        string minpStr;
        string maxpStr;
        try
        {
 
            if (e.Item.ItemType == ListItemType.AlternatingItem ||
                e.Item.ItemType == ListItemType.Item)
            {
                Panel pnlmore = (Panel)e.Item.FindControl("pnlMore");
                Panel pnlmodel = (Panel)e.Item.FindControl("pnlmodel");
                Panel pnlmodel_r = (Panel)e.Item.FindControl("pnlmodel_r");
                Panel pnlcat = (Panel)e.Item.FindControl("pnlCatTop");
 
                string modelId = ((DataRowView)(e.Item.DataItem))["ModelID"].ToString();
                string Model_Name = ((DataRowView)(e.Item.DataItem))["Model_Name"].ToString();
 
                if (Model_Name == Declarations.Str_Cat_Top)
                {  // dealing with case of category top name
                    pnlmore.Visible = false;
                    pnlmodel.Visible = false;
                    pnlmodel_r.Visible = false;
                    pnlcat.Visible = true;
 
                    string Cat_name_s = ((DataRowView)(e.Item.DataItem))["Cat_Name"].ToString();
                    HPstrProductURL = "~/models.aspx?cat=" + System.Web.HttpUtility.UrlEncode(Cat_name_s);
                    HyperLink Hpcattop = (HyperLink)e.Item.FindControl("HLCatTop");
                    Hpcattop.NavigateUrl = HPstrProductURL;
                    numitems++;
                }
                else
                if (Model_Name == Declarations.Str_More_Top) 
                {  // dealing with case of nore link
                    pnlmore.Visible = true;
                    pnlmodel.Visible = false;
                    pnlmodel_r.Visible = false;
                    pnlcat.Visible = false;
 
                    string Cat_name_s = ((DataRowView)(e.Item.DataItem))["Cat_Name"].ToString();
 
                    HPstrProductURL = "~/models.aspx?cat=" + System.Web.HttpUtility.UrlEncode(Cat_name_s);
                    HyperLink Hp1 = (HyperLink)e.Item.FindControl("HLModelNameM");
                    Hp1.NavigateUrl = HPstrProductURL;
                    numitems = 0;
                }
                else
                {
                    if (numitems == 1)
                    {
                        // dealing of case of regular nodel left side
                        pnlmore.Visible = false;
                        pnlmodel.Visible = true;
                        pnlmodel_r.Visible = false;
                        pnlcat.Visible = false;
 
                        HPstrProductURL = "~/product.aspx?model_name=" + Model_Name;
 
                        HyperLink Hp1 = (HyperLink)e.Item.FindControl("HLModelName");
                        Hp1.NavigateUrl = HPstrProductURL;
 
                        HyperLink Hp2 = (HyperLink)e.Item.FindControl("HLimgModel");
                        Hp2.NavigateUrl = HPstrProductURL;
 
                        Button btncomp = (Button)e.Item.FindControl("btnComparep");
                        btncomp.PostBackUrl = HPstrProductURL;
 
                        Label lblMin = (Label)e.Item.FindControl("lblMinPrice");
                        minpStr = String.Format("{0:C}", decimal.Parse(lblMin.Text));
                        lblMin.Text = minpStr.ToString();
 
                        Label lblMax = (Label)e.Item.FindControl("lblMaxPrice");
                        maxpStr = String.Format("{0:C}", decimal.Parse(lblMax.Text));
                        lblMax.Text = maxpStr.ToString();
 
                        Image i1 = (Image)e.Item.FindControl("ImgModel");
                        strURL = ServerAddr + "vg_paint?s=main&w=80&bg=bg1&h=60&q=85&f=models/" + modelId + ".jpg";
 
 
                        i1.ImageUrl = strURL;
                        i1.AlternateText = Model_Name;
                        numitems++;
                    }
                    else if (numitems == 2)
                    {
                        // dealing of case of regular nodel right side
                        pnlmore.Visible = false;
                        pnlmodel.Visible = false;
                        pnlmodel_r.Visible = true;
                        pnlcat.Visible = false;
 
                        HPstrProductURL = "~/product.aspx?model_name=" + Model_Name;
 
                        HyperLink Hp1_r = (HyperLink)e.Item.FindControl("HLModelName_r");
                        Hp1_r.NavigateUrl = HPstrProductURL;
 
                        HyperLink Hp2_r = (HyperLink)e.Item.FindControl("HLimgModel_r");
                        Hp2_r.NavigateUrl = HPstrProductURL;
 
                        Button btncomp_r = (Button)e.Item.FindControl("btnComparep_r");
                        btncomp_r.PostBackUrl = HPstrProductURL;
 
                        Label lblMin_r = (Label)e.Item.FindControl("lblMinPrice_r");
                        minpStr = String.Format("{0:C}", decimal.Parse(lblMin_r.Text));
                        lblMin_r.Text = minpStr.ToString();
 
                        Label lblMax_r = (Label)e.Item.FindControl("lblMaxPrice_r");
                        maxpStr = String.Format("{0:C}", decimal.Parse(lblMax_r.Text));
                        lblMax_r.Text = maxpStr.ToString();
 
                        Image i1_r = (Image)e.Item.FindControl("ImgModel_r");
                        strURL = ServerAddr + "vg_paint?s=main&w=80&bg=bg1&h=60&q=85&f=models/" + modelId + ".jpg";
 
 
                        i1_r.ImageUrl = strURL;
                        i1_r.AlternateText = Model_Name;
                        numitems++;
                    }
                }
 
            }
        }
        catch (Exception ex)
        {
            using (ErrorLog Err = new ErrorLog(ex, ""))
            {
                Err.logErrorString();
            }
        }
    }

Open in new window

0
 
SteveH_UKCommented:
Hi Anat.  Sorry I've not been able to write back to you until now.

The markup you are now using looks much better.  You might want to consider combining the header and footer into a single table with the content.  You can use the colspan attribute to indicate cells that should occupy more than one column.  This ensures your layout is consistent, after all, the four items should be one table, right?  You then can choose whether or not to combine all the rows into a single table (with 4 rows per group).  You can then move the <table> element into a HeaderTemplate and the closing element </table> into the FooterTemplate.

I guess the way I would have gone about this is to construct a new data class representing the four rows, for example:

struct RowOneData {
  ...
}
struct RowTwoData {
  ...
}
struct RowThreeData {
  ...
}
struct RowFourData {
  ...
}

struct MyDataItem {
  RowOneData row1;
  RowTwoData row2;
  RowThreeData row3;
  RowFourData row4;
}

Then I would set the DataSource property on the Repeater to a generic List:

List<MyDataItem> items = new List<MyDataItem>();
// Populate items
RPModels.DataSource = items;
RPModels.DataBind();

Then, in the repeater I wouldn't have to work out which row I was dealing with, as I could use the item directly, for example:

<ItemTemplate>
  <table>
    <tr><td>Title</td><td>
      <asp:Literal ... Text='<%# ((MyDataItem)Container.DataItem).row1.Title %>' />
    </td></tr>
    <tr>
      <td>
        <asp:Literal ... Text='<%# ((MyDataItem)Container.DataItem).row2.Text %>' />
      </td>
      <td>
        <asp:Literal ... Text='<%# ((MyDataItem)Container.DataItem).row3.Text %>' />
      </td>
    </tr>
    <tr><td>Footer</td><td>
      <asp:Literal ... Text='<%# ((MyDataItem)Container.DataItem).row4.Footer %>' />
    </td></tr>
  </table>
</ItemTemplate>
     
---

I'm afraid I won't take technical questions by e-mail, but you should be able to contact me by following my LinkedIn link on my expert profile in this site.  Or you can carry on asking questions here, and I'll do my best to respond.
0
 
ANAT2403Author Commented:
Hi Steven,
Well first thanks for the new ideas but you will not believe what I did. I was asked to write this issue without a repeater in the design html with datatable that consist only the items without the addition of header and footer and dealing with this in the html code. and I did it and it work.  and this cocern the subject  I would like to advise with you which is a general subject:
I am writing my site in asp.net with controls of dot net like repeater textbox and many server controls. but in my work I get complains that my code is doing many postbacks, that HTMl people do not understand this code, that the page is not passing many search engines because of the viewstate lines and so on. for example in this case I was told that there are many panels in my code which is not good for the html.  and I  am asked to use less server controls and more regular asp controls.
What I am doing now is trying to enter some regular asp controls in places I can.
I would like to hear you opinion on this subject as I am getiing mixed up with what I think and the demands I get. Of course the main demand is that the page will come up quickly.
thankyou
anat
0
 
SteveH_UKCommented:
I think the people that are advising you have no idea what they are talking about!

The viewstate is a hidden input control on a form, and certainly won't cause issues with search engines.  In any case, you can control whether or not to use ViewState on a page-by-page and control-by-control basis, but you should use it for controls that you need to record state for between post-backs.

Panels are converted to DIVs and are absolutely fine in HTML markup.

Postbacks can be controlled so that they happen when you need them to and not otherwise.  Your code may not be taking advantage of client-side processing, or may be causing unnecessary postbacks.  That is a question of reviewing your code and understanding what it is trying to do.

There is no reason why the "HTML people" should understand the code.  The page is constructed on each request dynamically.

Really, it tells me that they don't understand dynamic pages.

Reducing the size of the page, and also improving the time it takes to render, is a question of trimming the page and using caching.  I can't give direct guidance on this because it depends on your page.  The technology isn't at fault, but you may need to improve your use of it.

Finally, a repeater doesn't make a page slow by itself.
0
 
ANAT2403Author Commented:
Hi Steveh,
Thanks for your comments.
Two questions:
If I have controls that are not needed in a postback is it good to use non server controls?
How do you suggest me to improve the use of trimming the page and using caching? DO you have any good article with examples?
By the way in the beginning I used the menu control and it caused me very big viewstate hidden variables that I could see when I did view source on the page. SO I changed it to a javascript menu.
What do you think about it?
Concerning the problem of this quetion I have to do it in any case with a datatable that does not include the header and footer. This has to be dealt in the page.
Thankyou and I hope I don't spent too nuch of your time.
Anat
0
 
SteveH_UKCommented:
You should only apply the runat="server" attribute to controls that need server-side processing.  Once you've added that tag, there is little performance difference in server-side HTML and server-side ASP.NET controls.

Trimming is best accomplished by following the preceeding statement.  Then, have a look at the output and decide if it is too much.  Output caching can be considered afterwards if there is still a problem.

Menu controls always use a lot of data, whether in JavaScript or in ViewState.  As I earlier stated, using lots of ViewState shouldn't be an issue in any case, unless you have very limited bandwidth.
0
All Courses

From novice to tech pro — start learning today.