How to increase row of a repeater as text increases? I am using a repeater to display image , and image description .if image description contains more character , the text is overlapping with the other rows . how can i solve this problem?
<HeaderTemplate>
<div class="HeaderStyle">
<div class="HeaderStyle5">Edit</div>
<div class="HeaderStyle5">Delete</div>
<div class="HeaderStyle1">Image</div>
<div class="HeaderStyle2">ImageDescription</div>
</div>
<ul id="defaultList">
</HeaderTemplate>
<ItemTemplate>
<li id='item_<%# Container.ItemIndex + 1 %>' originalId='<%# DataBinder.Eval(Container.DataItem, "ImageId") %>' class="itemStyle">
<div class="itemStyle">
<div class="itemStyle4"> <asp:HyperLink ID="LinkButton2" runat="server" Text="Edit" NavigateUrl='<%#Request.Url.AbsoluteUri+"&ImageId="+ DataBinder.Eval(Container.DataItem, "ImageId") %>'></asp:HyperLink> </div>
<div class="itemStyle5">
<asp:LinkButton ID="lnkDelete" runat="server"
CommandName='<%# DataBinder.Eval(Container.DataItem, "ImageId") %>' CommandArgument='<%# DataBinder.Eval(Container.DataItem, "SortId") %>' OnClientClick="return confirm('Are you sure , you want to delete..?');" OnCommand="Calling_Delete" >Delete</asp:LinkButton> </div>
<div class="itemStyle1"><asp:Image ID="Image1" runat="server" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "ImageUrl") %> ' Height="50px" Width="50px" /> </div>
<div><%# DataBinder.Eval(Container.DataItem, "ImageDesc") %> </div>
</div>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
Use
myRepeater.Attributes["Style"] = "OVERFLOW-Y:auto;";
Related
How to add header to the Repeater control? I want to add the header for each columns mentioned
Below is my repeater control
<asp:Repeater ID="rptSingleSapDataInfo" runat="server">
<ItemTemplate>
<div class="widget-box widget-blue">
<div class="widget-main widget-repeater-horizontal">
<div class="pull-left">
<asp:Label ID="lblSapId" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "SAP_ID") %>' CssClass="labelbold"></asp:Label>
</div>
<div class="pull-right">
<asp:Label ID="lblState" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "STATE") %>' CssClass="labelbold"></asp:Label>
</div>
<div class="pull-right">
<asp:Label ID="lblNLat" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "NEW_LATITUDE") %>' CssClass="labelbold"></asp:Label>
</div>
<div class="pull-right">
<asp:Label ID="lblNLong" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "NEW_LONGITUDE") %>' CssClass="labelbold"></asp:Label>
</div>
<div class="pull-right">
<asp:Label ID="lblOLat" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "OLD_LATITUDE") %>' CssClass="labelbold"></asp:Label>
</div>
<div class="pull-right">
<asp:Label ID="lblOLong" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "OLD_LONGITUDE") %>' CssClass="labelbold"></asp:Label>
</div>
<div class="pull-right1" style="padding: 5px 5px 5px 20px;">
<asp:Label ID="lblRemarks" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "REMARKS") %>' CssClass="labelbold"></asp:Label>
</div>
<div class="pull-right">
<asp:Label ID="lblCreatedBy" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "CREATED_BY") %>' CssClass="labelbold"></asp:Label>
</div>
<div class="pull-right">
<asp:Label ID="lblCreatedDate" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "CREATED_DATE", "{0:dd-MM-yyyy}") %>' CssClass="labelbold"></asp:Label>
</div>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
You are already using the ItemTemplate so use the HeaderTemplate to add a header:
<asp:Repeater ID="rptSingleSapDataInfo" runat="server">
<HeaderTemplate>
My header
</HeaderTemplate>
<ItemTemplate>
<div class="widget-box widget-blue">
...
</div>
</ItemTemplate>
</asp:Repeater>
As i understand your question use Header Template
<asp:Repeater runat="server" ID="rowRepeater" OnItemDataBound="rowRepeater_ItemBound">
<HeaderTemplate>
<table>
<tr>
<asp:Repeater runat="server" ID="headerRepeater">
<ItemTemplate>
<th>
<%# Container.DataItem %>
</th>
</ItemTemplate>
</asp:Repeater>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:Label runat="server" ID="lblUserName" Text='<%# Eval("Key") %>' /></td>
<asp:Repeater runat="server" ID="columnRepeater">
<ItemTemplate>
<td>
<asp:HiddenField runat="server" ID="hfRoleIndex" Value='<%# Container.ItemIndex %>' />
<asp:CheckBox runat="server" ID="cbColumnValue" Checked='<%# Container.DataItem %>' OnCheckedChanged="cbColumnValue_CheckedChanged" AutoPostBack="true" />
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
Here is the reference link
Repeater and add columns to header and itemtemplate on page load
it will help you
I have binding to <UL> using repeater control.
<ul id="menu-content" class="menu-content collapse out">
<asp:Repeater ID="rptMenu" runat="server" OnItemDataBound="rptMenu_OnItemBound">
<ItemTemplate>
<li data-toggle="collapse" data-target="#li<%# ((RepeaterItem)Container).ItemIndex + 1%>" class="collapsed active"><a id="A1">
<asp:HiddenField ID="HiddenField1" runat="server" Value='<%#Eval("Id") %>' />
<%#Eval("Name")%>
<span class="arrow"></span></a>
</li>
<ul class="sub-menu collapse" id="li<%# ((RepeaterItem)Container).ItemIndex + 1%>">
<asp:Repeater ID="rptChildMenu" runat="server">
<ItemTemplate>
<li>
<a id="A2" href='<%#Eval("Name") %>' runat="server"><%#Eval("Name")%></a>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
</ItemTemplate>
</asp:Repeater>
</ul>
If there are no sub-menu item(s), arrow icon should be hidden or should not be rendered:
<span class="arrow"></span>
I'm trying to get the value of txt_MRP in the codebehind but it keeps giving me
The name "txt_MRP" doesn't exist in this current context
Why is this reference not available? How can I get it?
(The button that I am pressing is btn_add_to_cart_Click)
<div class="row">
<div class="col-lg-2"></div>
<div class="col-lg-4">
<asp:DataList ID="DataList3" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<ul id="etalage">
<li>
<img id="Img1" class="etalage_thumb_image" runat="server" src='<%# Eval("Fotografia1") %>' />
<img id="Img2" class="etalage_source_image" runat="server" src='<%# Eval("Fotografia2") %>' />
</li>
</ul>
<br />
</ItemTemplate>
</asp:DataList>
</div>
<div class="col-lg-6">
<asp:DataList ID="DataList1" runat="server" DataKeyField="ID" DataSourceID="SqlDataSource1" >
<ItemTemplate>
<div id="product_name_width">
<asp:Label ID="Product_nameLabel" runat="server" CssClass="product_name" Text='<%# Eval("Nombre") %>' />
<br />
</div>
<span id="rs">₡</span><asp:Label ID="MRPLabel" CssClass="price" runat="server" Text='<%# Eval("Precio") %>' />
<br />
<br />
<span id="brand_name">Marca</span>
<asp:Label ID="BrandLabel" runat="server" CssClass="brand" Text='<%# Eval("Marca") %>' />
<br />
</div>
<div class="form-group">
<label> Cantidad </label>
<asp:TextBox CssClass="form-control" ID="txt_MRP" runat="server" ></asp:TextBox>
</div>
<div id="buy_now_css" runat="server">
<ul>
<li>
<asp:Button ID="btn_add_to_cart" CssClass="btn btn-primary" runat="server" Text="Añadir al Carrito" OnClick="btn_add_to_cart_Click" />
</li>
<li>
<asp:Button ID="btn_buy_now" CssClass="btn btn-success" runat="server" Text="Comprar" OnClick="btn_buy_now_Click" />
</li>
</ul>
</div>
</ItemTemplate>
</asp:DataList>
<asp:DataList ID="DataList2" runat="server" DataKeyField="ID" DataSourceID="SqlDataSource1">
<ItemTemplate>
<h2>Descripcion</h2>
<div id="Description_width">
<asp:Label ID="DetailLabel" CssClass="description" runat="server" Text='<%# Eval("Descripcion") %>' />
</div>
</ItemTemplate>
</asp:DataList>
</div>
</div>
txt_MRP does not exist because it is in a DataList Control. It is only available inside the scope of the Control.
If you want to get the value you have to use another method.
Change the button event from Onclick to OnCommand and add a CommandName and set the ItemIndex as CommandArgument.
<asp:Button ID="btn_add_to_cart" CommandName="addToCart" CommandArgument='<%# Container.ItemIndex %>' CssClass="btn btn-primary" runat="server" Text="Añadir al Carrito" OnCommand="btn_add_to_cart_Command" />
And in code behind
protected void btn_add_to_cart_Command(object sender, CommandEventArgs e)
{
//check the correct commandname
if (e.CommandName == "addToCart")
{
//get the row number from the commandargument
int itemIndex = Convert.ToInt32(e.CommandArgument);
//find the texbox in the correct row with findcontrol
TextBox textBox = DataList1.Items[itemIndex].FindControl("txt_MRP") as TextBox;
//do stuff with the value
Label1.Text = textBox.Text;
}
}
You have to assign the delegate or button. For instance:
var button = new Button();
button.Click += new EventHandler("btnAddToCart");
You also may need a CommandArgument, to be able to send a specific value back. But to actually register the click event would be like the above.
I have on ListView
<asp:ListView ID="MyListView" runat="server">
<LayoutTemplate>
<ul class="menu">
<li><i></i>home</li>
<li runat="server" />
<li class="myClass">
<a title="SomeTitle" href="example.com/default.aspx">
</a>
</li>
</ul>
<ascx:Menu runat="server" Visible="true" />
</LayoutTemplate>
<ItemTemplate>
<li>
<asp:HyperLink runat="server" NavigateUrl='<%# Eval("URL") %>'
Text='<%# Eval("Title") %>'/></li>
</ItemTemplate>
<SelectedItemTemplate>
<li class="active">
<asp:HyperLink runat="server" NavigateUrl='<%# Eval("URL") %>'
Text='<%# Eval("Title") %>' /></li>
</SelectedItemTemplate>
</asp:ListView>
on .cs file I have one string
protected string CurrentName = MyMethod();//that return a string or null
in aspx page I want to show in <LayoutTemplate> different structure of tags in dependecy of my CurrentName
I try like this:
<% if(this.CurrentName ==null){ %>
<ul class="menu">
<li><i></i>home</li>
<li runat="server" />
<li class="myClass">
<a title="SomeTitle" href="example.com/default.aspx">
</a>
</li>
</ul>
<ascx:Menu runat="server" Visible="true" />
<% } else { %>
<ul class="menu">
<li><i></i>home</li>
<li class="myClass">
<ascx:Menu runat="server" Visible="true" />
</li>
</ul>
<% } %>
this method not work, how use IF statements in ASPX page right?
I would implement this with two panels which have exlusive conditions on Visible attribute, so that only one of them is rendered at a single load:
<asp:Panel runat="server" Visible='<%# this.CurrentName == null %>'>
<ul class="menu">
<li><i></i>home</li>
<li runat="server" />
<li class="myClass">
<a title="SomeTitle" href="example.com/default.aspx">
</a>
</li>
</ul>
<ascx:Menu runat="server" Visible="true" />
</asp:Panel>
<asp:Panel runat="server" Visible='<%# this.CurrentName != null %>'>
<ul class="menu">
<li><i></i>home</li>
<li class="myClass">
<ascx:Menu runat="server" Visible="true" />
</li>
</ul>
</asp:Panel>
I have a Repeater which contains Eval commands and a Button (Which I can't access) I would like to access this button and when clicked insert one of the Eval commands (Eg. Car Model) into a listbox I have on the same page.
<asp:Button ID="modelButton" CommandArgument='<%# Eval("Model") %>' Text='<%# "Add Model to List:" + Eval("Model") %>' runat="server" />
<asp:Repeater ID="Repeater2" runat="server" DataSourceID="AccessDataSource1" DataMember="DefaultView" OnItemDataBound="Repeater2_ItemDataBound">
<ItemTemplate>
<div>
<p><img src="carImages/<%#Eval("Artwork")%>" /></div>
<div class="col-xs-4">
<h4><%# Eval("Make")%> (<%# Eval("Year") %>)</h4>
<p><%# Eval("Model")%></p>
<p><%# Eval("Colour")%></p>
<p><%# Eval("Type")%></p>
<div>
<asp:Button ID="modelButton" CommandArgument='<%# Eval("Model") %>' Text='<%# "Add Model to List:" + Eval("Model") %>' runat="server" />
</div>
</a>
</div>
</ItemTemplate>
Just add your oncommand argument to the repeated button
<asp:Button ID="modelButton" CommandArgument='<%# Eval("Model") %>' OnCommand="CommandBtn_Click" Text='<%# "Add Model to List:" + Eval("Model") %>' runat="server" />
you can grab the eval in the behind code
void CommandBtn_Click(Object sender, CommandEventArgs e){
var command = e.CommandArgument;
// Do whatever with it here
}
That will get the evaluated model