dynamically change css class name - css

Below is my code:
<asp:ListView ID="lViewMenu" runat="server">
<ItemTemplate>
<li class="context-menu-group"><span class="color-bar color-13"></span>
<asp:LinkButton ID="lbtnMenu" runat="server" Text='<%# Eval("MenuName")%>' OnClick="lbtnMenu_Click"></asp:LinkButton>
</li>
</ItemTemplate>
</asp:ListView>
And i need to change the class name of <li> to context-menu-group active when a LinkButton is clicked on the onclick() How?

Related

hyper link button Target __blank not working while click image within repeater control

My asp code like this
<asp:Repeater ID="Repeater1" runat="server" Visible="true">
<ItemTemplate>
<asp:HyperLink ID="imgbtnHl" runat="server" Target="_blank"> // hyper link btn am givem target equal to blank but it is not working/
<asp:ImageButton runat="server" Width="300px"ID="imgbtnHospitalimg" ImageUrl=images/tt.png" />/while click the image i want new window not an popup/
</asp:HyperLink>
Don't use image button inside hyperlink instead of that use simple img tag.
referrer below code i have tested working fine.
<asp:Repeater ID="Repeater1" runat="server" Visible="true">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" Target="_blank" NavigateUrl="~/Default3.aspx" Text='<%# Eval("Name") %>'><img src="Good-mark.png" /></asp:HyperLink>
</ItemTemplate>
</asp:Repeater>

Dynamic menu with ASP.NET repeater

Currently i'm familiarizing myself with ASP.NET and i've stuck on a problem with dynamic content inside "ItemTemplate" of "Repeater". Here is my code:
<asp:Repeater ID="sidebarRepeater" runat="server">
<ItemTemplate>
<li>
<%# DataBinder.Eval(Container.DataItem, "Name") %>
</li>
</ItemTemplate>
</asp:Repeater>
I'm getting a list of links with href == Id of current item and text of this item.
The problem is, that i need a "Onclick" asp.net handler for each of those links (this is menu of "Master" User control, and on each click i shall change contents of child user control, according to selected item in master).
Any tips?
Edit: I've already tryed to use LinkButton like:
<li>
<asp:LinkButton ID='<%# DataBinder.Eval(Container.DataItem, "Id") %>' runat="server" OnClick="ChangeSomething">
<%# DataBinder.Eval(Container.DataItem, "Name") %>
</asp:LinkButton>
</li>
Edit2: Currently my markup looks like this:
<li>
<input type="hidden" value="<%# DataBinder.Eval(Container.DataItem, "Id") %>"
<asp:LinkButton runat="server" ID="LinkButton_Office" Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>'/>
</li>
In this case, it draws only a "hidden input" element only for first item in repeater.
Edit3: full listing of what i currently have(only <li></li> rendered into actual HTML):
<div class="row">
<div class="twelve column">
<div class="row">
<div class="side-bar">
<nav>
<ul>
<asp:Repeater ID="sidebarRepeater" runat="server">
<ItemTemplate>
<li>
<asp:LinkButton ID="linkSidebar" runat="server" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "Id") %>' Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>' OnClick="linkMenu_Click"></asp:LinkButton>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
</nav>
</div>
<div class="page">
<asp:PlaceHolder runat="server" ID="contentPlaceholder" />
</div>
</div>
</div>
</div>
Also i forgot to say, that this is actually a .Net user control for Umbraco project.
Datasource is attached for repeater in protected void Page_Load(object sender, EventArgs e) method.
Please try like this
<asp:Repeater ID="sidebarRepeater" runat="server">
<ItemTemplate>
<asp:LinkButton ID="linkMenu" runat="server" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "Id") %>' Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>' OnClick="linkMenu_Click"></asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
This will keep "Id" field in CommandArgument and "Name" field in Text properties
In linkMenu_Click event handeler, you will get the Id and Name values as the sample code
protected void linkMenu_Click(object sender, EventArgs e)
{
LinkButton link = (LinkButton)sender;
string id = link.CommandArgument;
string name = link.Text;
//Implement the different display of each menu here ...
}
Problem solved, by adding <form runat="server"> around my <nav> tag.
Seems like every of <asp:button\linkbutton> needs that in order to work properly.

How to get the ID of a LinkButton that was previously clicked in a Repeater control?

I have a repeater control that has a LinkButton in it. Using command argument, I perform necessary functions in the code-behind. I want to turn the forecolor of a LinkButton to red after it is clicked and if another LinkButton is clicked in the Repeater, I want to turn off the previously clicked LinkButton to black and the recently clicked one to red. How do I do that? Here is my code:
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
<asp:LinkButton ID="LinkButton1" runat="server" Text='<%#Eval("divisionlabel") %>'
OnCommand="LinkButton1_Command" CommandName="MyPendingApps" CommandArgument='<%#Eval("divisionid") %>'>
</asp:LinkButton>
</li>
</ItemTemplate>
<FooterTemplate>
<li>
<asp:LinkButton ID="LinkButton_InsReqList" runat="server" OnCommand="LinkButton_InsReqList_Command"
CommandName="InspectionRequests">Inspection Requests List</asp:LinkButton>
</li>
</ul>
</FooterTemplate>
</asp:Repeater>
Add a OnClick="LinkButtons_Click" in every linkbutton on the form
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
<asp:LinkButton ID="LinkButton1" runat="server" Text='<%#Eval("divisionlabel") %>'
OnCommand="LinkButton1_Command" CommandName="MyPendingApps" CommandArgument='<%#Eval("divisionid") %>' OnClick="LinkButtons_Click">
</asp:LinkButton>
</li>
</ItemTemplate>
<FooterTemplate>
<li>
<asp:LinkButton ID="LinkButton_InsReqList" runat="server" OnCommand="LinkButton_InsReqList_Command"
CommandName="InspectionRequests" OnClick="LinkButtons_Click">Inspection Requests List</asp:LinkButton>
</li>
</ul>
</FooterTemplate>
</asp:Repeater>
and the code for that function is:
protected void LinkButtons_Click(object sender, EventArgs e)
{
LinkButton link=(LinkButton)sender;
if (link.ID == "yourDesiredID1")
{
link.ForeColor=System.Drawing.Color.Red;
}
else
{
link.ForeColor=System.Drawing.Color.YourDefaultdColor;
}
if (link.ID == "yourDesiredID2")
{
link.ForeColor=System.Drawing.Color.Yellow;
}
else
{
link.ForeColor=System.Drawing.Color.YourDefaultColor;
}
if (link.ID == "yourDesiredID3")
{
link.ForeColor=System.Drawing.Color.Blue;
}
else
{
link.ForeColor=System.Drawing.Color.YourDefaultColor;
}
}
I would store a unique identifier (value, Id, ItemIndex etc) from the the ItemCommand event server side in ViewState and then in the ItemDataBound event check if unique indentifier equals that of the value in ViewState, if it does apply the class that changes the text colour to red, if not carry on binding.
Obviously there are some suttleties here that you need to think about but its a start.

How to get the parent item index inside child repeater?

I have nested repeaters like this:
<asp:Repeater ID="rptQuestoes" runat="server">
<HeaderTemplate>
<ol class="orderedList">
</HeaderTemplate>
<ItemTemplate>
<li>
<%#DataBinder.Eval(Container.DataItem, "QuestionName")%>
<asp:Repeater ID="rptAlternativas" DataSource='<%# Container.DataItem.Row.GetChildRows("Questionario") %>' runat="server">
<HeaderTemplate>
<ul style="list-style-type: none">
</HeaderTemplate>
<ItemTemplate>
<li>
<input id="rb" type="radio" name='ITEM_INDEX_HERE' value='<%#Container.DataItem("AlternativeID")%>' /><%#Container.DataItem("AlternativeName")%>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</li>
</ItemTemplate>
<FooterTemplate>
</ol>
</FooterTemplate>
</asp:Repeater>
I want to print the parent item index inside the child repeater (rptAlternativas) in VB right in ITEM_INDEX_HERE marker. How can I achieve this?
I hope someone can give you a better answer than this, but I would consider adding a property to your "Quentionario" sub elements.
<asp:Repeater ID="rptAlternativas"
DataSource='<%# Container.DataItem.Row.GetChildRows("Questionario") %>'
runat="server">
Can you add a question id to each of these objects? You're already binding to their AlternativeId in your radio button, adding a question id to these objects would let you do simply:
<input id="rb" type="radio" name='<%#Container.DataItem("QuestionId")%>' value='<%#Container.DataItem("AlternativeID")%>' />
Even if these objects are auto-generated from an ORM, you should be able to add the property in via a partial class, and then just set the appropriate values in a simple loop.

Building dynamic links with Repeater control

I am rendering data using Repeater control.
Let's say there are 2 fields in the data source: productName and ProductID
In the following code:
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
<%#Eval("productName")%> <br/>
<asp:HyperLink ID="lnkDetails" runat="server" NavigateUrl="~/Details.aspx?ID=">See Details</asp:HyperLink>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
What do I need to modify in
<asp:HyperLink ID="lnkDetails" runat="server" NavigateUrl="~/Details.aspx?ID=">See Details</asp:HyperLink>
to include value retreived from the ProductID in the link NavigateUrl="~/Details.aspx?ID="
NavigateUrl="~/Details.aspx?ID=<%# Eval("productID") %>" should work...
... but it doesn't!
The most elegant way should be:
<asp:HyperLink ID="lnkDetails" runat="server" NavigateUrl='<%# Eval("ProductID", "~/Details.aspx?ID={0}") %>'>See Details</asp:HyperLink>

Resources