I have been trying to apply Eval on textbox which its mode is TextMode="Date". The date is not loading in to the text box and this is because the textmode. It seems to be that the Eval format is not working at all. When I remove the textmode it works. I have been trying several on variations and non of them have worked.
Here is some of them:
<asp:TextBox ID="birthdayTB" runat="server" Text='<%# Convert.ToDateTime(Eval("Birthday")).ToString("d") %>' TextMode="Date"></asp:TextBox>
<asp:TextBox ID="birthdayTB" runat="server" Text='<%# Eval("Birthday", "{0:dd-MM-yyyy}") %>' TextMode="Date"></asp:TextBox>
<asp:TextBox ID="birthdayTB" runat="server" Text='<%# Eval("Birthday", "{0:d}") %>' TextMode="Date"></asp:TextBox>
How can I make this work?
Thank you.
Use on code behind
birthdayTB.Text = Convert.ToDateTime(Birthday).ToString("dd-MM-yyyy");
Related
I have a Gridview contains many Template-Fields.
I want to make the width of a label in my html source equal to a value saved in my database. Here is the code I am trying but it is not working:
<asp:TemplateField HeaderText="Status" ItemStyle-Width="200px">
<ItemTemplate>
<asp:Label BackColor="#6699ff" Width="<%#
Eval("Status").ToString() %>" runat="server"> </asp:Label>
<%# Eval("Status").ToString() %>%
</ItemTemplate>
</asp:TemplateField>
U can do something like this:
span.gridLabel
{
display:block;
/*You can change to display:inline-block if you want Label and %Value in same line.*/
}
And your template field:
<asp:TemplateField HeaderText="Status" ItemStyle-Width="200px">
<ItemTemplate>
<span class="gridLabel" style='width:<%# Eval("Status").ToString() %>px; Background:#6699ff'> </span>
<%# Eval("Status").ToString() %>%
</ItemTemplate>
</asp:TemplateField>
I am trying to build a three level left navigation for my application using asp.net repeater and html list
I have three nested repeater with a linkbutton inside
when i click the linkbutton the list class should be active ( i have css for this active class).I am not good in Jquery
below is my code ( now i used only two repeater),Kindly help me how can i do this?
<ul class="nav nav-list mb-xl show-bg-active">
<asp:repeater ID="rep1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<li class="">
<asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Eval("Menu") %>'></asp:LinkButton>
<asp:repeater ID="rep2" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<ul>
<li>
<asp:LinkButton ID="LinkButton2" CommandArgument="id" runat="server" Text='<%# Eval("Menu") %>'></asp:LinkButton>
</li> </ul>
</ItemTemplate>
</asp:repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:KTCWEBConnectionString %>" SelectCommand="SELECT NAVIAGATE_1.Menu FROM NAVIAGATE INNER JOIN NAVIAGATE AS NAVIAGATE_1 ON NAVIAGATE.ID = NAVIAGATE_1.ParentID WHERE (NAVIAGATE.Menu = #menu)">
<SelectParameters>
<asp:ControlParameter ControlID="LinkButton1" Name="menu" PropertyName="text" />
</SelectParameters>
</asp:SqlDataSource>
</li>
</ItemTemplate>
</asp:repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:KTCWEBConnectionString %>" SelectCommand="SELECT DISTINCT Menu, ParentID, ID FROM NAVIAGATE WHERE (NOT (ParentID IS NULL)) AND (ParentID = 2)"></asp:SqlDataSource>
</ul>
So it's been a while since I've done ASP.Net controls but...
Your inner lists would need to bind the Enabled property to something in your Controller. Then when something is clicked you just set that binding to false. This should in turn disable all those buttons and if your css is written correctly (tier2:disabled) it should pick it up correctly.
That said, if this is a new application, stop using ASP.NET controls, it should have been killed a long time ago. HTML + CSS + ReactJs or KnockoutJs is the way to go now-a-days!
i want to open link in new tab how to change my code to open link in new tab
<button onclick="location.href='<%#Eval("ReportLinks")%>'," title='<%#Eval("ReportLinks")%>'> Link</button>
Use a small t instead of a capital T for target like this:
<ItemTemplate> </asp:Label>
</ItemTemplate>
<asp:TemplateField HeaderText="Total Unique Links">
<ItemTemplate><a href='LinkDetails.aspx?val1=total' Target="_blank"><asp:Label ID="lblUsername" ForeColor="#1A0DAB" ToolTip="all links report" runat="server" Text='<%# Eval ("Total") %>' ></asp:Label>
</a>
</ItemTemplate>
Ok guys, I know this question has been asked a million times. I've searched for days and none of the online solutions found actually work for me. Here's my code:
<asp:SqlDataSource
ID="SqlDataSource2"
runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT VTPNAME, NETWORKKEY, FKVTPDOMAIN, VLANNUMBER, NETDESCRIPTION, BEGINNINGIP,
HOSTS, DEFAULTGATEWAY FROM NETWORK.NETWORK, NETWORK.VTPDOMAIN WHERE
NETWORK.FKVTPDOMAIN = VTPDOMAIN.VTPDOMAINKEY"
DeleteCommand="DELETE FROM NETWORK.NETWORK WHERE NETWORKKEY =: NETWORKKEY"
UpdateCommand="UPDATE NETWORK.NETWORK SET FKVTPDOMAIN =:updateFKVTP, VLANNUMBER = :VLANNUMBER,
NETDESCRIPTION = :NETDESCRIPTION,BEGINNINGIP = :BEGINNINGIP,
HOSTS = :HOSTS,DEFAULTGATEWAY = :DEFAULTGATEWAY WHERE NETWORKKEY = :NETWORKKEY"
InsertCommand="INSERT INTO NETWORK.NETWORK (VLANNUMBER,NETDESCRIPTION,BEGINNINGIP,HOSTS,DEFAULTGATEWAY,FKVTPDOMAIN) VALUES (:vlanNet,:descNet,:begIpNet,:hostNet,:defNet,:vtpdomainkey)">
<InsertParameters>
<asp:ControlParameter Name="vlanNet" ControlID="vlanTextbox" />
<asp:ControlParameter Name="descNet" ControlID="descTextbox" />
<asp:ControlParameter Name="begIpNet" ControlID="beginIPTextbox" />
<asp:ControlParameter Name="hostNet" ControlID="hostsTextbox" />
<asp:ControlParameter Name="defNet" ControlID="defaultGatTextBox" />
<asp:ControlParameter Name="vtpdomainkey" ControlID="vtpDomainFKDropDown" />
</InsertParameters>
<UpdateParameters>
<asp:ControlParameter Name="updateFKVTP" ControlID="vtpNameDropDownUpdate" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:GridView
ID="GridView2"
runat="server"
AutoGenerateColumns="False"
DataSourceID="SqlDataSource2"
AllowPaging="True"
AllowSorting="True"
DataKeyNames="NETWORKKEY"
Width="650px"
OnRowUpdating="GridView2_RowUpdating">
<Columns>
<asp:CommandField HeaderText="Options" ShowDeleteButton="True" ShowEditButton="True" />
<asp:TemplateField HeaderText="VTP Domain" SortExpression="VTPNAME">
<EditItemTemplate>
<asp:DropDownList ID="vtpNameDropDownUpdate" runat="server" DataSourceID="SqlDataSource6" DataTextField="VTPNAME" DataValueField="VTPDOMAINKEY">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("VTPNAME") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Here's the actual error given:
Could not find control 'vtpNameDropDownUpdate' in ControlParameter 'updateFKVTP'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Could not find control 'vtpNameDropDownUpdate' in ControlParameter 'updateFKVTP'.
Everything works as is supposed to, except the dropDownList. It will NOT find it, I have tried dollar signs, colons,underscore, you name it, to tell it where the control is and no result. They are in the same and they both lay one under the other, just as I posted it here. I got the first row to actually update because I tried the method where you right click on the dropdownlist while running and you "inspect the element" and copy and paste the whole ControlID string into the ControlParameter ControlID. The problem is, there are several rows, so it will only work for the one element I inspected and not all the other ones. Any help would be appreciated and thank you in advance for your time!
-Fernando
The DropDownList is inside The Template Control, so you should find the template control first.In this example template control is in 7th column of Gridview. after find template inside that you can find DropDownList :
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
var index = e.RowIndex;
var dropDownctr= GridView1.Rows[index].Controls[6].FindControl("vtpNameDropDownUpdate")
}
I have a program that dynamically creates various text boxes / drop down lists. I am trying to figure out how to validate these fields only when one is changed. Basically if someone entered a date in the text box then I need the program to validate that the drop down list was changed or vice versa. If there are no changes to both fields then it should not validate. Any help would be extremely appreciated. Here is the code:
<asp:TemplateField HeaderText="ValidatedDate" SortExpression="ValidatedDate">
<EditItemTemplate>
<asp:TextBox ID="txtValDate" Width="100px" MaxLength="10" runat="server" AutoPostBack="true"
Text='<%# Bind("ValidatedDate","{0:MM/dd/yyyy}") %>'></asp:TextBox>
<asp:RegularExpressionValidator ValidationGroup="g1" ID="RegularExpressionValidator10"
runat="server" ControlToValidate="txtValDate" Display="None" ErrorMessage="Validated Date: ##/##/####"
ValidationExpression="\d{1,2}/\d{1,2}/\d{4}"></asp:RegularExpressionValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblValidatedDate" runat="server" Text='<%# Bind("ValidatedDate","{0:MM/dd/yyyy}")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ProductStatus" SortExpression="ProductStatusDescription">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList4" runat="server" DataSourceID="SqlDataSource6" AutoPostBack="true"
DataTextField="StatusDescription" DataValueField="StatusID" SelectedValue='<%# Bind("Status") %>'>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblProductStatus" runat="server" Text='<%# Bind("ProductStatusDescription")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
My apologies, the code can be a bit confusing without the correct context.
ebyrob, thank you for your help. I figured it out however and it works beautifully. Here is the code that fixed it all:
protected void AddError(string errorMessage)
{
cstValidate.IsValid = false;
cstValidate.ErrorMessage = errorMessage;
cstValidate.EnableClientScript = false;
}
protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox txtValidatedDate = GridView2.Rows[e.RowIndex].FindControl("txtValDate") as TextBox;
DropDownList ddlStatusCompare = GridView2.Rows[e.RowIndex].FindControl("dropdownlist4") as DropDownList;
if (txtValidatedDate.Text == string.Empty && ddlStatusCompare.SelectedValue == "1")
{
AddError("Please enter a Validated Date");
e.Cancel = true;
}
else if (txtValidatedDate.Text != string.Empty && ddlStatusCompare.SelectedValue == "0"
|| txtValidatedDate.Text != string.Empty && ddlStatusCompare.SelectedValue == "99")
{
AddError("Please remove the Validated Date");
e.Cancel = true;
}
if (!e.Cancel)
Helpers.LogChanges(GridView2, e, _employeeID, "SaleProducts");
}