This is my code :
<asp:Repeater runat="server" ID="rpUbicazione">
<ItemTemplate>
<div class="Field" style="margin-bottom:20px;">
// elements
</div>
</ItemTemplate>
</asp:Repeater>
and I'd like to hide first element. So I tried changing first line with :
<asp:Repeater runat="server" ID="rpUbicazione" Visible="<%# (Container.ItemIndex != 0) %>">
but seems it doesnt works : ItemIndex it is not a method.
How can I do it?
Try this:
<asp:Repeater runat="server" ID="rpUbicazione">
<ItemTemplate>
<div class="Field" style='margin-bottom: 20px; display: <%# Container.ItemIndex == 0 ? "none" : "block" %>'>
// elements
</div>
</ItemTemplate>
</asp:Repeater>
or you can do something like this:
<script runat="server">
protected void rpUbicazione_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemIndex == 0)
{
e.Item.FindControl("divElement").Visible = false;
}
}
</script>
<asp:Repeater runat="server" ID="rpUbicazione" onitemdatabound="rpUbicazione_ItemDataBound">
<ItemTemplate>
<div id="divElement" runat="server" class="Field" style="margin-bottom: 20px;">
// elements
</div>
</ItemTemplate>
</asp:Repeater>
Related
How can i change imageUrl in listview function. I tried some codes but not worked.
my codes
protected void DoTheCommand(object sender, ListViewCommandEventArgs e)
{
if (e.CommandName == "Button")
{
ImageButton img = (ImageButton)e.Item.FindControl("Button1");
img.ImageUrl = "/img/heartcirc.png";
html code
<asp:ListView ID="listUrunler" OnItemCommand="DoTheCommand" runat="server">
<ItemTemplate>
<div class="col-lg-3 col-md-6 mb-4 mb-lg-0">
<div class=" card-img-top rounded shadow-sm border-0">
<asp:ImageButton ID="ImageButton1" class="card-img" runat="server" ImageUrl='<%# Eval("urunResim") %>' PostBackUrl='<%# String.Format("UrunDetay.aspx?Id={0}",Eval("Id")) %>' />
<div class="card-body p-4">
<h5 class="card-title" style="margin-top: -20px"><%# Eval("urunBaslik") %></h5>
<div class="price text-success" style="justify-content: center; float: left;"><%# Eval("urunFiyat") %>TL</div>
<asp:ImageButton ID="Button1" runat="server" Width="20px" Height="20px" ImageUrl="/img/heart.png" CommandName="Button" CommandArgument='<%# Eval("Id") %>' Text="Add to Cart" />
<div style="clear: both;"></div>
</div>
</div>
</div>
</ItemTemplate>
</asp:ListView>
Thanks for helps.
When I click on Flag button all operation to be perform by button click are working very well but it take nearly 7 8 seconds to Show effects on screen..
My Asp.net code:
<asp:ScriptManager runat="server" EnablePartialRendering="true" ID="SC1"></asp:ScriptManager>
<!-- Get Mile-->
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-7">
<%-- <asp:UpdatePanel runat="server" ID="UpdatePanel1">
<ContentTemplate>--%>
<ul class="timeline-list">
<asp:Repeater runat="server" ID="repeater_post" OnItemDataBound="repeater_post_ItemDataBound" OnItemCreated="repeater_post_ItemCreated">
<ItemTemplate>
<li class="media media-clearfix-xs">
<div class="media-body">
<div class="media-body-wrapper">
<div class="panel panel-default ">
<asp:Image runat="server" ID="img_PostPic" ImageUrl='<%# GetImagePath(Eval("ImagePath").ToString()) %>' CssClass="img-responsive" Style="height: 200px !important; width: 526px !important" />
<%--<asp:Image runat="server" ID="Image1" ImageUrl='<%# GetMood(Eval("Mood").ToString()) %>' class="pull-right" />--%>
<div class="view-all-comments">
<asp:UpdatePanel runat="server" ID="upd5" UpdateMode="Always">
<ContentTemplate>
<asp:LinkButton runat="server" CommandArgument='<%# Eval("PostID").ToString() %>' ID="lbtn_Flag" CssClass="btn btn-white" ToolTip='<%# GetAllFlagMember(Convert.ToString(Eval("PostID"))) %>' OnClick="lbtn_Flag_Click" Visible='<%# CheckFlag(Eval("PostID"))%>'>
<i class="fa fa-flag"></i>
</asp:LinkButton>
<asp:LinkButton runat="server" CommandArgument='<%# Eval("PostID") %>' ID="lbtn_Unflag" CssClass="btn btn-white" ToolTip='<%# GetAllFlagMember(Convert.ToString(Eval("PostID"))) %>' OnClick="lbtn_Unflag_Click" Visible='<%# CheckUnFlag(Eval("PostID"))%>'>
<i class="fa fa-flag"></i> Unflag
</asp:LinkButton>
<strong> <%# GetFlagCount(Eval("PostID").ToString())%> Flag</strong>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="lbtn_Flag" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="lbtn_Unflag" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<%--<asp:LinkButton runat="server" ID="lbtnflagmember" CommandArgument='<%# Eval("PostID")%>' Text='<%# GetFlagCount(Eval("PostID").ToString())%>'></asp:LinkButton>--%>
<!-- Go to www.addthis.com/dashboard to customize your tools -->
<div class="addthis_sharing_toolbox" style="float: right"></div>
<asp:LinkButton runat="server" CommandArgument='<%# Eval("Lat")+"$"+Eval("Long")+"$"+Eval("PostAutorID")+"$"+Eval("Destination") %>' ID="lbtn_MapCanvas" ToolTip="Map" OnClick="lbtn_MapCanvas_Click" CssClass="pull-right" CausesValidation="false"> <i class="fa fa-map-marker"></i> Navigate
</asp:LinkButton>
<asp:LinkButton runat="server" CommandArgument='<%# Eval("PostID")+"$"+Eval("Destination") %>' ID="lbtn_ReportAbuse" ToolTip="Report Abuse" OnClick="lbtn_ReportAbuse_Click" CssClass="pull-right"> <i class="fa fa-share-square-o "></i> Report Abuse
</asp:LinkButton>
</div>
</div>
</div>
</div>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
My C# Back end Code on link buttons is :
protected void lbtn_Flag_Click(object sender, EventArgs e)
{
//lbtn_Flag.Enabled = false;
//lbtn_Unflag.Enabled = true;
LinkButton btn = (LinkButton)sender;
int _PostId = Convert.ToInt32(btn.CommandArgument);
WStblFlag wsFlag = new WStblFlag();
string res = wsFlag.AddFlag(_PostId, Functions.ParseInteger(Convert.ToString(Session["ProfileID"])));
GetPost();
//UpdatePanel up = repeater_post.FindControl("upd5") as UpdatePanel;
//up.Update();
//UpdatePanel inner_rpt = (UpdatePanel)repeater_post.Items.FindControl("repeater_Comment");
}
/// <summary>
/// UnFlag the post
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lbtn_Unflag_Click(object sender, EventArgs e)
{
//lbtn_Flag.Enabled = true;
//lbtn_Unflag.Enabled = false;
LinkButton btn = (LinkButton)sender;
int _PostId = Convert.ToInt32(btn.CommandArgument);
WStblFlag wsFlag = new WStblFlag();
string res = wsFlag.UnFlagPost(_PostId, Functions.ParseInteger(Convert.ToString(Session["ProfileID"])));
GetPost();
}
I already try many things to reduce response time but it wont succeed...
Ty..
I have a nested repeater that contains a CheckBox control.
<asp:Repeater runat="server" ID="optionalRepeater" OnItemDataBound="CheckCompCondiments">
<HeaderTemplate>
<div class="sectionHeader" style="font-weight: bold; font-size: 13pt; text-decoration: underline; margin: 20px 0px 15px 0px;">
Product Extras
</div>
</HeaderTemplate>
<ItemTemplate>
<div class="col-md-4" style="border: 1px solid #ccc; margin: 5px;">
<asp:HiddenField runat="server" ID="salesMenuID" Value='<%#Eval("sales_menu_id") %>' />
<asp:HiddenField runat="server" ID="minVal" Value='<%#Eval("minVal") %>' />
<asp:HiddenField runat="server" ID="maxVal" Value='<%#Eval("maxVal") %>' />
<p>
<asp:Label runat="server" ID="condHdr" style="text-decoration: underline;" Text='<%#Eval("sales_menu_desc") %>'></asp:Label>
</p>
<asp:Repeater runat="server" ID="compMenuRadio">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<asp:HiddenField runat="server" ID="hdPriLvl"/>
<input type="radio" name="compSelect" runat="server"/>
</ItemTemplate>
<FooterTemplate>
<hr/>
</FooterTemplate>
</asp:Repeater>
<asp:Repeater runat="server" ID="compMenuCheck">
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
<asp:HiddenField runat="server" ID="hdPriLvl" Value='<%#Eval("pPriceLvl") %>' />
<asp:CheckBox runat="server" ID='compSelected' CssClass='<%# Eval("pcode") %>' Text='<%# Eval("pdesc") %> '/>
<%--<input type="checkbox" id="compSelect" runat="server" value='<%#Eval("pCode") %>'/>--%>
<%-- <%#Eval("pDesc") %>--%>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
<asp:DropDownList runat="server" ID="compSelect" Visible="False" style="width: 98%; margin: 5px 0px 5px 0px;"/>
</div>
</ItemTemplate>
</asp:Repeater>
On my Server Side I have the following code:
if (optionalRepeater.Items.Count > 0)
{
foreach (RepeaterItem compItem in optionalRepeater.Items)
{
HtmlInputHidden priLvlVal = (HtmlInputHidden)compItem.FindControl("hdPriLvl");
foreach (Control compCtrl in compItem.Controls)
{
if (compCtrl.GetType() == typeof(CheckBox))
{
CheckBox checkBox = (CheckBox)compCtrl;
CheckBox chk = (CheckBox) checkBox;
if (checkBox.Checked)
{
string prod = checkBox.CssClass;
string childGuiud = Guid.NewGuid().ToString("N").ToUpper();
hasCondiment = true;
ShoppingCart.Instance.AddItem(prod, childGuiud, mainGuid, Session["transactionGuid"].ToString(), priLvlVal.Value, hasCondiment, 1, null);
checkBox.Checked = false;
}
}
}
}
}
My code get as far as this line
if (compCtrl.GetType() == typeof(CheckBox))
But never makes it inside the if statement. When I am expecting the type to be CheckBox it says literal Control.
Can anyone see anything that I could be doing wrong, I have been looking at this for a while now and I can't seem to get any further.
Thanks,
Somango!
If you use an ItemTemplate you have to use FindControl to get the reference of the controls inside:
foreach (RepeaterItem compItem in optionalRepeater.Items)
{
HtmlInputHidden priLvlVal = (HtmlInputHidden)compItem.FindControl("hdPriLvl");
CheckBox compSelect = (CheckBox)compItem.FindControl("compSelect");
if (checkBox.Checked)
{
// ...
}
}
By looping the RepeaterItem.Controls property you just find a single Literal control which is the container for every control in the ItemTemplate. So you could loop compItem.Controls[0].Controls to find your CheckBox. But in my opinion using compItem.FindControl is much more readable.
I have a service page, which shows service details and has a sub-section like service features and charges. I created two repeaters for features and charges. Please refer to the following sql tables image for more information:
But I have no idea how to bind this hierarchical data to nested repeaters. Here is my code:
<!--Nested Repeater Section-->
<asp:Repeater ID="ServiceDetailsRepeater" runat="server"
onitemdatabound="ServiceDetailsRepeater_ItemDataBound">
<ItemTemplate>
<asp:HiddenField ID="service_id" runat="server" Value='<%#Eval("Id")%>'/>
<h3><a name='<%#Eval("Id")%>'></a><%#Eval("Service_name")%></h3>
<img src='<%# "images/"+ Eval("ImageName")%>' alt="picture" width="48" height="48" class="img" />
<p><%#Eval("Service_desc")%></p>
<div id="Div1" class="clr" runat="server"> </div>
<div id="Div2" class="box" runat="server">
<div id="Div3" class="box_t" runat="server">
<asp:Panel ID="Panel_ServiceFeature" runat="server" class="box_b">
<h2>Features</h2>
<ul style="font-family:Arial, Helvetica, sans-serif;font-size:11px;color:#5f5f5f">
<asp:Repeater ID="ServiceFeatureRepeater" runat="server">
<ItemTemplate>
<li><%#Eval("Feature_Text")%></li>
</ItemTemplate>
</asp:Repeater>
</ul>
</asp:Panel>
</div>
</div>
<div id="Div5" class="clr" runat="server"> </div>
<div id="Div6" class="box" runat="server">
<div id="Div7" class="box_t" runat="server">
<asp:Panel ID="Panel_ServiceCharge" runat="server" class="box_b">
<h2>Charges</h2>
<table style="font-family:Arial, Helvetica, sans-serif;font-size:11px;color:#5f5f5f">
<tr><td></td>
<td>Rs.</td><td> </td><td align="left">Months</td></tr>
<asp:Repeater ID="ServiceChargeRepeater" runat="server">
<ItemTemplate>
<tr>
<td><img src="images/sub_nav.gif" width="18px" height="14px" alt=""/></td>
<td>Rs. <%#String.Format("{0:#,###}", Eval("Charges_Per_Month"))%></td>
<td> </td>
<td><%#Eval("No_Of_Month")%> Months</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</asp:Panel>
</div>
</div>
<div id="Div9" class="clr" runat="server"></div>
</ItemTemplate>
</asp:Repeater>
<!--End Section-->
Finally, my web site page this is my live web site service page view. This page is static but now I want to bind this service details with database.
One way to do it is to simply bind the DataSource property of the inner Repeater to a suitable collection. E.g. something like:
<asp:Repeater ID="ServiceDetailsRepeater" runat="server"
DataSourceID="SqlDataSource1">
<asp:Repeater ID="ServiceFeatureRepeater" runat="server"
DataSource="<%# DatabaseHelper.GetFeatures(Eval("Id")) %>">
...
</asp:Repeater>
<asp:Repeater ID="ChargesRepeater" runat="server"
DataSource="<%# DatabaseHelper.GetCharges(Eval("Id")) %>">
...
</asp:Repeater>
</asp:Repeater>
i have also check if no features or charges are found to particular service then panel have to off. so i directly doing from code behind
UPDATE
If you're more comfortable doing it from code-behind, go ahead, but you could also do it declaratively by databinding the Repeater's Visible property, e.g.:
...
<asp:Repeater ID="ServiceFeatureRepeater" runat="server"
DataSource="<%# DatabaseHelper.GetFeatures(Eval("Id")) %>"
Visible="<%# DatabaseHelper.HasFeatures(Eval("Id")) %>"
>
...
</asp:Repeater>
....
if (!Page.IsPostBack)
{
ServiceListRepeater.DataSource = DatabaseHelper.GetSummaryOfActiveServices();
ServiceListRepeater.DataBind();
ServiceDetailsRepeater.DataSource = DatabaseHelper.GetSummaryOfActiveServices();
ServiceDetailsRepeater.DataBind();
}
protected void ServiceDetailsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
RepeaterItem item = e.Item;
if ((item.ItemType == ListItemType.Item) ||(item.ItemType == ListItemType.AlternatingItem))
{
HiddenField service_id = (HiddenField)item.FindControl("service_id");
Repeater service_features = (Repeater)item.FindControl("ServiceFeatureRepeater");
service_features.DataSource = DatabaseHelper.GetFeatureSummary(int.Parse(service_id.Value.ToString()));
service_features.DataBind();
if (service_features.Items.Count == 0)
{
Panel Panel_ServiceFeature = (Panel)item.FindControl("Panel_ServiceFeature");
Panel_ServiceFeature.Visible = false;
}
Repeater service_charges =(Repeater)item.FindControl("ServiceChargeRepeater");
service_charges.DataSource = DatabaseHelper.GetChargeSummary(int.Parse(service_id.Value.ToString()));
service_charges.DataBind();
if (service_charges.Items.Count == 0)
{
Panel Panel_ServiceCharge = (Panel)item.FindControl("Panel_ServiceCharge");
Panel_ServiceCharge.Visible = false;
}
}
}
My situation looks like this: I've got x-axis scrollable div that contains buttons with numbers of page displayed. This div is placed in data list inside User Control responsible for displaying news on my site.
This is the code of this div and datalist with page numbers.
<div style="width:430px; overflow:auto; overflow-y:hidden; -ms-overflow-y:hidden; vertical-align:top; position:relative; top:-1px; ">
<asp:DataList ID="dlPaging" runat="server" OnItemCommand="dlPaging_ItemCommand" RepeatDirection="Horizontal"
OnItemDataBound="dlPaging_ItemDataBound">
<ItemTemplate>
<asp:Button ID="lnkbtnPaging" class="pagebutton" runat="server" CommandArgument='<%# Eval("PageIndex") %>'
CommandName="lnkbtnPaging" Text='<%# Eval("PageText") %>' CausesValidation="False" />
</ItemTemplate>
</asp:DataList>
</div>
How to mantain x-axis position of this div after postback? I've tried several tricks, javascript and I can't figure it out.
Any reason not to use an UpdatePanel?
<div id="divDtPaging" runat="server" visible="true" style="width: 50%; overflow: scroll; text-align: center">
<asp:DataList runat="server" ID="dtPaging" OnItemCommand="dtPaging_ItemCommand"
OnItemDataBound="dtPaging_ItemDataBound" RepeatDirection="Horizontal"
SeparatorStyle-Wrap="true" Style="height: auto">
<ItemTemplate>
<asp:LinkButton runat="server" ID="lnkbtnPaging" Text="PageText" CommandArgument="PageIndex" Style="padding-right: 5px">
</asp:LinkButton>
</ItemTemplate>
</asp:DataList>
</div>
<asp:HiddenField id="hdnScrollPos" runat="server"/>
<script type="text/javascript">
function BeginRequestHandler(sender, args)
{
document.getElementById('<%=hdnScrollPos.ClientID %>').value = document.getElementById('<%=divDtPaging.ClientID %>').scrollLeft;
}
function EndRequestHandler(sender, args) {
document.getElementById('<%=divDtPaging.ClientID %>').scrollLeft = document.getElementById('<%=hdnScrollPos.ClientID %>').value;
}
if (window.Sys && Sys.WebForms && Sys.WebForms.PageRequestManager) {
var prm = Sys.WebForms.PageRequestManager.getInstance()
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequestHandler);
}
</script>