I have a repeater column like this
<asp:Label id="lbl1" runat="server"><a href='mailto:<%# DataBinder.Eval(Container.DataItem, "EMAIL1_GPD") %>'
target='_blank'> <%# DataBinder.Eval(Container.DataItem, "FIRSTNAME1_GPD") %>
<%# DataBinder.Eval(Container.DataItem, "LASTNAME1_GPD") %></a> </asp:Label>
<br/>
<asp:Label ID="lblPhone" runat="server" Text='<%# Eval("PHONE1_GPD") %>' Visible='<%# Eval("PHONE1_GPD") == null ? false: true %>'
ForeColor="#000000" Font-Size="Small"></asp:Label>
<br/>
<asp:Label id="Label12" runat="server"><a href='mailto:<%# DataBinder.Eval(Container.DataItem, "EMAIL2_GPD") %>'
target='_blank'><%# DataBinder.Eval(Container.DataItem, "FIRSTNAME2_GPD")%>
<%# DataBinder.Eval(Container.DataItem, "LASTNAME2_GPD")%></a> </asp:Label>
<br/>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("PHONE2_GPD") %>' Visible='<%# Eval("PHONE2_GPD") == null ? false: true %>'
ForeColor="#000000" Font-Size="Small"></asp:Label>
<br/>
<asp:Label id="Label13" runat="server"><a href='mailto:<%# DataBinder.Eval(Container.DataItem, "EMAIL3_GPD") %>'
target='_blank'><%# DataBinder.Eval(Container.DataItem, "FIRSTNAME3_GPD")%>
<%# DataBinder.Eval(Container.DataItem, "LASTNAME3_GPD")%></a> </asp:Label>
<br/>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("PHONE3_GPD") %>' Visible='<%# Eval("PHONE3_GPD") == null ? false: true %>'
ForeColor="#000000" Font-Size="Small"></asp:Label>
</td>
I would like to hide the labels when dataBinder.Eval is empty. I have done it for the labels where it displays phone number. I am stuck with hiding the hrefs. Though it does not display anything when the data is null. The page on the browser does not display properly.
Set visibility of the label like Visible='<%# String.IsNullOrEmpty(Eval("EMAIL3_GPD")) ? false : true %>'. Your label should look like:
<asp:Label id="Label13" runat="server" Visible='<%# String.IsNullOrEmpty(Eval("EMAIL3_GPD")) ? false : true%>'><a href='mailto:<%# DataBinder.Eval(Container.DataItem, "EMAIL3_GPD") %>'
target='_blank'><%# DataBinder.Eval(Container.DataItem, "FIRSTNAME3_GPD")%>
<%# DataBinder.Eval(Container.DataItem, "LASTNAME3_GPD")%></a> </asp:Label>
Related
In the repeater Item template, can i make the colour of alternate one difFerent.ie..1 blue next white,next blue,white...like that.
In this Item template i have a header division and Detail division.I want the Header division to have alternate colour like grid view.Is it possible..?
thanks
<ItemTemplate>
<div id='h<%# DataBinder.Eval(Container, "ItemIndex") %>' class="header"
onclick='ToggleDisplay(<%# DataBinder.Eval(Container, "ItemIndex") %>);' style="border-style: none;">
<asp:Panel ID="Panel3" runat="server" Height="30px" BorderStyle="Groove" BackColor="#00D9D9">
<%# DataBinder.Eval(Container.DataItem, "License")%
<%# DataBinder.Eval(Container.DataItem, "LicenseName")%
<%# DataBinder.Eval(Container.DataItem, "StartDate")%
<%# DataBinder.Eval(Container.DataItem, "Renewal")%>
</asp:Panel>
</div>
<div id='d<%# DataBinder.Eval(Container, "ItemIndex") %>' class="details">
<asp:Panel ID="Panel2" runat="server" Height="195px" BackColor="Gray" Font-Bold="False" ForeColor="Maroon">
<br />
<asp:Label ID="Label1" runat="server" Text="LicenseID"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"LicenseID") %>' Enabled="False" BackColor="Gray" BorderStyle="None"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text="License Name"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"LicenseName")%>' Enabled="false" BackColor="Gray" BorderStyle="None"></asp:TextBox>
</asp:Panel>
</div>
</ItemTemplate>
You can use the AlternatingItemTemplate to specify the format of alternating items. Here is a simple example:
<asp:Repeater id="Repeater1" runat="server">
<HeaderTemplate>
<table border="1">
</HeaderTemplate>
<AlternatingItemTemplate>
<tr>
<td style="background-color:Blue">
<b><%# Container.DataItem %></b>
</td>
</tr>
</AlternatingItemTemplate>
<ItemTemplate>
<tr>
<td style="background-color:White">
<%# Container.DataItem %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
For more information see: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.alternatingitemtemplate.aspx
<div id='h<%# DataBinder.Eval(Container, "ItemIndex") %>' class="header"
onclick='ToggleDisplay(<%# DataBinder.Eval(Container, "ItemIndex") %>);' style="border-style: none;">
<asp:Panel ID="Panel3" runat="server" Height="30px" BorderStyle="Groove" BackColor="#00D9D9">
<%# DataBinder.Eval(Container.DataItem, "License")%>
<%# DataBinder.Eval(Container.DataItem, "LicenseName")%>
<%# DataBinder.Eval(Container.DataItem, "StartDate")%>
<%# DataBinder.Eval(Container.DataItem, "Renewal")%>
</asp:Panel>
</div>
<div id='d<%# DataBinder.Eval(Container, "ItemIndex") %>' class="details">
<asp:Panel ID="Panel2" runat="server" Height="195px" BackColor="Gray" Font-Bold="False" ForeColor="Maroon">
<br />
<asp:Label ID="Label1" runat="server" Text="LicenseID"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"LicenseID") %>' Enabled="False" BackColor="Gray" BorderStyle="None"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text="License Name"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"LicenseName")%>' Enabled="false" BackColor="Gray" BorderStyle="None"></asp:TextBox>
</asp:Panel>
</div>
</ItemTemplate>
<AlternatingItemTemplate>
<div id='h<%# DataBinder.Eval(Container, "ItemIndex") %>' class="header"
onclick='ToggleDisplay(<%# DataBinder.Eval(Container, "ItemIndex") %>);' style="border-style: none;">
<asp:Panel ID="Panel3" runat="server" Height="30px" BorderStyle="Groove" BackColor="#f0e68c">
<%# DataBinder.Eval(Container.DataItem, "License")%>
<%# DataBinder.Eval(Container.DataItem, "LicenseName")%>
<%# DataBinder.Eval(Container.DataItem, "StartDate")%>
<%# DataBinder.Eval(Container.DataItem, "Renewal")%>
</asp:Panel>
</div>
<div id='d<%# DataBinder.Eval(Container, "ItemIndex") %>' class="details">
<asp:Panel ID="Panel2" runat="server" Height="195px" BackColor="Gray" Font-Bold="False" ForeColor="Maroon">
<br />
<asp:Label ID="Label1" runat="server" Text="LicenseID"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"LicenseID") %>' Enabled="False" BackColor="Gray" BorderStyle="None"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text="License Name"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"LicenseName")%>' Enabled="false" BackColor="Gray" BorderStyle="None"></asp:TextBox>
</asp:Panel>
</div>
</AlternatingItemTemplate>
</asp:Repeater>
i have a gridview that show comments. i want that if a person likes a comment, press a like button and i increse the sum of likes , but i do not want to connect to database and bind. i want do that using ajax. how can i do that?
here is my code:
<asp:UpdatePanel runat="server" id="UpdatePanel" >
<ContentTemplate>
<asp:GridView ID="grdCommentsForLoginnedUser"
runat="server"
AutoGenerateColumns="False"
Width="100%"
OnRowCommand="grdCommentsForLoginnedUser_RowCommand"
ViewStateMode="Inherit">
<Columns>
<asp:TemplateField >
<ItemTemplate>
<asp:HiddenField ID="hdnCommentID" runat="server"
Value='<%# Bind("CommentID") %>'/>
<table border="2" dir="rtl">
<tr>
<td rowspan="2" style="background-color: #6699FF" width="200px">
<asp:HyperLink ID="lnkCommenterName"
runat="server"
NavigateUrl='<%# Bind("CommenterProfile") %>'
Text='<%# Bind("CommenterName") %>' />
</td>
<td width="700px">
<br />
<asp:Label ID="lblCommentText" runat="server"
Text='<%# Bind("CommentText") %>' />
<br />
</td>
</tr>
<tr>
<td width="700px">
<asp:Label ID="lblPreviousAcceptOrNonAccept" runat="server"
Text='<%# Bind("PersonPreviousAcceptOrNonAccept") %>' />
<asp:LinkButton ID="lnkBtnRemovePreviousAcceptOrNonAccept"
runat="server"
Text='<%# Bind("RemovePersonPreviousAcceptOrNonAccept") %>'
CommandName="RemovePreviousAcceptOrNonAccept"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
<br />
<asp:LinkButton ID="lnkBtnUpRate" runat="server" Text="Like"
Visible='<%# Bind("isLikeAndUnlikeButtonVisible") %>'
CommandName="LikeComment"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
<br />sum of likes
<asp:Label ID="lblCommentLikes" runat="server"
Text='<%# Bind("CommentLikes") %>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
Add a client side onClick javascript to each button. When clicked get the parent td tag and then getElementById("lblCommentLikes") to set the .innerText property of the "lblCommentLikes" span.
+(theTD.getElementById("lblCommentLikes").innerText)+=1;
or
+(theTD.getElementById("lblCommentLikes").innerText)-=1;
Tip: If you are using IE then press F12 to inspect the DOM of a running page
Hi I am trying to implement a nested user control in listview and the user control doesn't get bound.
Here is my code.
<asp:ListView ID="ListViewTaskList" runat="server" DataKeyNames="TaskID"
DataSourceID="SqlDataSourceTaskList" OnItemDataBound="ListViewTaskListItemDataBound" ItemPlaceholderID="itemPlaceholder">
<LayoutTemplate>
<div class="ListView ">
<div style="font-size:2em;color:#555555;margin-bottom:20px;">Task List</div>
<div ID="itemPlaceholder" runat="server">
</div>
</div>
</LayoutTemplate>
<ItemTemplate>
<div class="rlvI">
<asp:Label ID="TaskIDLabel" runat="server" Text='<%# Eval("TaskID") %>' />
<asp:Label ID="TaskLabel" runat="server" Text='<%# Eval("Task") %>' />
<asp:Label ID="CreatedDateLabel" runat="server" Text='<%# Eval("CreatedDate") %>' />
<asp:Label ID="UpdatedDateLabel" runat="server" Text='<%# Eval("UpdatedDate") %>' />
<asp:Label ID="TimestampLabel" runat="server" Text='<%# Eval("Timestamp") %>' />
<asp:Label ID="TaskTypeIDLabel" runat="server" Text='<%# Eval("TaskTypeID") %>' />
<asp:Label ID="ProjectTaskStatusIDLabel" runat="server" Text='<%# Eval("ProjectTaskStatusID") %>' />
<asp:Label ID="SystemObjectIDLabel" runat="server" Text='<%# Eval("SystemObjectID") %>' />
<asp:Label ID="SystemObjectRecordIDLabel" runat="server" Text='<%# Eval("SystemObjectRecordID") %>' />
<asp:CheckBox ID="ActiveCheckBox" runat="server" Checked='<%# Eval("Active") %>' Enabled="false" />
<asp:Label ID="CreatedByAccountIDLabel" runat="server" Text='<%# Eval("CreatedByAccountID") %>' />
<asp:Label ID="UpdatedByAccountIDLabel" runat="server" Text='<%# Eval("UpdatedByAccountID") %>' />
<asp:Button ID="SelectButton" runat="server" CausesValidation="False" CommandName="Select" CssClass="rlvBSel" Text=" " ToolTip="Select" />
<div>
<Enet:Comments ID="Comments1" runat="server" systemObjectID='8' systemObjectRecordID="Comments1Init" />
</div>
</div>
</ItemTemplate>
<AlternatingItemTemplate>
<div class="rlvA">
<asp:Label ID="TaskIDLabel" runat="server" Text='<%# Eval("TaskID") %>' />
<asp:Label ID="TaskLabel" runat="server" Text='<%# Eval("Task") %>' />
<asp:Label ID="CreatedDateLabel" runat="server"
Text='<%# Eval("CreatedDate") %>' />
<asp:Label ID="UpdatedDateLabel" runat="server"
Text='<%# Eval("UpdatedDate") %>' />
<asp:Label ID="TimestampLabel" runat="server"
Text='<%# Eval("Timestamp") %>' />
<asp:Label ID="TaskTypeIDLabel" runat="server"
Text='<%# Eval("TaskTypeID") %>' />
<asp:Label ID="ProjectTaskStatusIDLabel" runat="server"
Text='<%# Eval("ProjectTaskStatusID") %>' />
<asp:Label ID="SystemObjectIDLabel" runat="server"
Text='<%# Eval("SystemObjectID") %>' />
<asp:Label ID="SystemObjectRecordIDLabel" runat="server"
Text='<%# Eval("SystemObjectRecordID") %>' />
<asp:CheckBox ID="ActiveCheckBox" runat="server"
Checked='<%# Eval("Active") %>' Enabled="false" />
<asp:Label ID="CreatedByAccountIDLabel" runat="server"
Text='<%# Eval("CreatedByAccountID") %>' />
<asp:Label ID="UpdatedByAccountIDLabel" runat="server"
Text='<%# Eval("UpdatedByAccountID") %>' />
<asp:Button ID="SelectButton" runat="server" CausesValidation="False"
CommandName="Select" CssClass="rlvBSel" Text=" " ToolTip="Select" />
<div>
<Enet:Comments ID="Comments1" runat="server" systemObjectID='8' '<%# Eval("TaskID") %>' />
</div>
</div>
</AlternatingItemTemplate>
``
I have been struggling with this problem for a few days now.
Please help!!
Please help!
if I look at your code, it seems to me that you aren't actually assigning the binding to anything:
<Enet:Comments ID="Comments1" runat="server" systemObjectID='8' '<%# Eval("TaskID") %>' />
try instead
<Enet:Comments ID="Comments1" runat="server" systemObjectID='8' YourProperty='<%# Eval("TaskID") %>' />
EDIT: in order to achieve two way data binding, one has to add BindableAttribute to the property on User Control
You can do easily:
<asp:Repeater ID="rptCityFriends" runat="server" OnItemDataBound="rptFriendsContainer_DataBound">
<ItemTemplate>
<asp:ImageButton ID="imgThumb" runat="server" PostBackUrl='<%# Eval("FBUsuarioID","~/Friends.aspx?friendID={0}") %>' ImageUrl='<%# Eval("FBAvatarUsuario") %>' CssClass="imgThumbs" />
</ItemTemplate>
</asp:Repeater>
But if i want to pass two Querystrings?I.E:
<asp:Repeater ID="rptCityFriends" runat="server" OnItemDataBound="rptFriendsContainer_DataBound">
<ItemTemplate>
<asp:ImageButton ID="imgThumb" runat="server" PostBackUrl='<%# Eval("FBUsuarioID","FBNomeUsuario","~/Friends.aspx?friendID={0}&nUser={1}") %>' ImageUrl='<%# Eval("FBAvatarUsuario") %>' CssClass="imgThumbs" />
</ItemTemplate>
</asp:Repeater>
How can I set two or more querystrings to an URL in "Eval DataBinding"?
Use String.Format(), i.e.
<asp:Repeater ID="rptCityFriends" runat="server" OnItemDataBound="rptFriendsContainer_DataBound">
<ItemTemplate>
<asp:ImageButton ID="imgThumb" runat="server" PostBackUrl='<%# String.Format("~/Friends.aspx?friendID={0}&nUser={1}", Eval("FBUsuarioID"), Eval("FBNomeUsuario")) %>' ImageUrl='<%# Eval("FBAvatarUsuario") %>' CssClass="imgThumbs" />
</ItemTemplate>
</asp:Repeater>
I have two datalists. One works like a menu where you click on a link to fill the othe datalist.
I also have added a next and previous linkbutton to move between the different "pages" so that you do not have to change using the menu datalist.
Now in code behind depending on which values I get from the database I add a RegularExpressionValidator.
This works great until I want to use the next button (or previous for that matter). Even if all the controls that are checked are valid when compared with the RegularExpressionValidator I never get to load the new values.
The next and previous buttons fires the datalist selected index change event and then I check if it is the previous or next button that was clicked.
But the previous and next buttons are numb. They don't even fire the event.
It is like clicking on the background. Nothing happens.
I have chcked the PageIs.Valid and it is true.
Does anyone have a clue what it could be that is causing this behavior?
Thanks in advance!
Some of the texts down there is in Swedish but it shouldn't matter for the code.
rev_checkfieldvalue.ControlToValidate = "tb_detailValue";
switch (iDataTypeId)
{
case 2:
rev_checkfieldvalue.ValidationExpression = #"^\d*[0-9 ]+$";
rev_checkfieldvalue.Text = "Fältet får endast innehålla siffror och mellanslag.";
break;
case 3:
break;
case 4:
break;
case 5:
rev_checkfieldvalue.ValidationExpression = #"\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*";
rev_checkfieldvalue.Text = "Fältet får endast innehålla en e-postadress.";
break;
}
e.Item.Controls.AddAt(32, rev_checkfieldvalue);
<asp:DataList ID="dl_componentInfo" DataKeyField="ComponentId" runat="server" OnItemDataBound="dl_componentInfo_OnItemDataBound" OnItemCommand="dl_componentInfo_OnItemCommand">
<ItemTemplate>
<table>
<tr>
<td colspan="2"><asp:Label ID="lb_componentName" SkinID="lblHeader" runat="server" Text='<%# Eval("ComponentName") %>' /></td>
</tr>
<tr>
<td colspan="2">Fält markerade med * är obligatoriska</td>
</tr>
<tr>
<td> </td>
<td>
<asp:DataList ID="dl_details" OnItemDataBound="dl_details_OnItemDataBound" runat="server">
<ItemTemplate>
<table>
<tr>
<td colspan="2">
<asp:Label ID="lbl_detailName" Text='<%# Eval("DetailName") %>' runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lbl_custDetName" runat="server" />
</td>
<td align="left">
<%--Always hidden values--%>
<asp:Label ID="lbl_detailTypeId" Visible="false" Text='<%# Eval("DetailTypeId") %>' runat="server" />
<asp:Label ID="lbl_detailId" Visible="false" Text='<%# Eval("DetailId") %>' runat="server" />
<asp:Label ID="lbl_dataTypeId" Visible="false" Text='<%# Eval("DataTypeId") %>' runat="server" />
<asp:Label ID="lbl_customerEventValueId" Visible="false" Text='<%# Eval("CustomerEventValueId") %>' runat="server" />
<asp:Label ID="lbl_reqFld" Visible="false" Text='<%# Eval("ReqFld") %>' runat="server" />
<%--Sometimes visible values--%>
<asp:Label ID="lbt_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server" />
<asp:Label ID="lbtb_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server" />
<asp:Label ID="lbth_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server" />
<asp:Label ID="lbc_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server" />
<asp:DropDownList ID="dd_detailValue" Visible="false" runat="server"></asp:DropDownList>
<%--Om det ska gå att markera/avmarkera alla så använd AJAX--%>
<asp:CheckBoxList ID="cbl_detailValue" RepeatDirection="Horizontal" RepeatLayout="flow" Visible="false" runat="server" />
<asp:CheckBox ID="cb_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server" />
<asp:TextBox ID="tb_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server" />
<asp:TextBox ID="ta_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server"></asp:TextBox>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</td>
</tr>
</table>
</ItemTemplate>
<FooterTemplate>
<table width="600">
<tr>
<td>
<asp:LinkButton id="lb_previous" Text="Föregående" CommandName="Previous" runat="server"/>
</td>
<td>
<asp:LinkButton id="lb_next" Text="Nästa" CommandName="Next" runat="server"/>
</td>
</tr>
</table>
</FooterTemplate>
</asp:DataList>
I thought I solved the issue but it just stopped checking.
So for case two you accept any non-empty string of digits and spaces.
Is that your intent?