This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Want to enable image button based on the value in the Gridview Field
I want to disable the gridview delete button if the status=1. 1 means already deleted.I am using the below code to disable the delete button it returns the error message "The server tag is not well formed.".
<asp:TemplateField ItemStyle-Width="20px" HeaderImageUrl="~/images/icn_trash.png" >
<ItemTemplate>
<asp:ImageButton ID="btn_delete" runat="server" Enabled="<%# (Eval("fld_status").ToString()=="0") ? "true" : "false" %>" ToolTip="Delete" OnClientClick="return confirm('Important Alert : Do you delete this item ?')" CommandName="del" CommandArgument='<%#Bind("fld_val_id") %>' ImageUrl="~/images/icn_trash.png" />
</ItemTemplate>
<ItemStyle Width="20px"></ItemStyle>
</asp:TemplateField>
Try escaping the quotes
Enabled="<%# (Eval(\"fld_status\").ToString()=="0") ? "true" : "false" %>"
you could also use single quotes like you did here
CommandArgument='<%#Bind("fld_val_id") %>'
I assume you should use ' here:
Enabled='<%# (Eval("fld_status").ToString()=="0") ? "true" : "false" %>'
Replace the " with ' and remove the "" around the booleans:
Enabled='<%# (Eval("fld_status").ToString()=="0") ? true : false %>'
Related
I'm wondering how I can use the Resources within the below Label - I'm not entirely sure.
The original line with a replacement "Yes" or "No":
<asp:Label runat="server" ID="someId" Text='<%# (Boolean.Parse(Eval("BooleanValue").ToString())) ? "Yes" : "No" %>'></asp:Label>
What I believed I could do with the resources:
<asp:Label runat="server" ID="someId" Text='<%# (Boolean.Parse(Eval("BooleanValue").ToString())) ? '<%$ Resources:language, Yes%>' : '<%$ Resources:language, No%>' %>'></asp:Label>
Any help would be appreciated, Thanks.
Okay, I got around this by declaring the variables in the code behind
protected string yes;
protected string no;
Then updating them once my page had loaded based on the culture the user set.
yes = language.ResourceManager.GetString("Yes",CultureInfo.CurrentCulture);
no = language.ResourceManager.GetString("No", CultureInfo.CurrentCulture);
Then using those in the statement
<asp:Label runat="server" ID="someId" Text='<%# (bool)Eval("BooleanValue") == false ? no.ToString() : yes.ToString() %>'></asp:Label>
I have a DropDownList on my page and I would like the DataTextField value to be based on a condition (language). I'm using Model Binding and this DropDown is nested in a bound FormView.
This is what I'm trying to do:
<asp:DropDownList ID="DropDownList1" ItemType="BLL.HelperClasses.ItemForList"
DataValueField="id" DataTextField="<%#: (this.IsEnglish) ? "en" : "fr" %>" SelectMethod="DropDownList1_GetData"
SelectedValue="<%#: Item.Claim.CurrencyID %>" runat="server"></asp:DropDownList>
.NET is complaining that my DataTextField "server tag is not well formed". IsEnglish is a boolean property in my base page.
Anyone know how to do this without using the code-behind?
I think you have to have "Eval" inserted so for it to actually compare them don't you?
<asp:label id="Label1" runat="server" text="<%# Eval("StReply") == true ? "yes" : "no" %>" xmlns:asp="#unknown">
</asp:label>
Code was used from http://www.codeproject.com/Questions/653888/using-If-statement-in-Bind-Eval
Problem was with the surrounding double-quotes. Changed them to single-quotes and everything works perfectly.
Final solution:
<asp:DropDownList ID="DropDownList1" ItemType="BLL.HelperClasses.ItemForList"
DataValueField="id" DataTextField='<%#: (this.IsEnglish) ? "en" : "fr" %>' SelectMethod="DropDownList1_GetData"
SelectedValue="<%#: Item.Claim.CurrencyID %>" runat="server"></asp:DropDownList>
This question already has answers here:
If statement in aspx page
(7 answers)
Closed 9 years ago.
New to asp.net ...
In DataList, ItemTemplate, I would like to check if value ("Exchange") in the DB is true.
If it's true I'd like to display a label with the text "True".
Please note Exchange is stored in the DB as
Was thinking about this, but no success yet.
<%#Eval("Exchange").ToString() == "True" ? "<asp:Label ID=\"Exchange\" runat=\"server\" Text=\"True"> </asp:Label>":""%>
Can anyone help?
Many thanks
The asp.net way of doing what you want to do is this.
<asp:Label ID="Exchange" runat="server" Text="True" Visible='<%# Eval("Exchange").ToString() == "True" %>' />
If Exchange is bool you do not require the ToString call
<asp:Label ID="Exchange" runat="server" Text="True" Visible='<%# Eval("Exchange") %>' />
I am not able to try it, but you can write the if for the text property. This should display a label with no text (therefore nothing visible) if the Eval("Exchange") returns something other than "True"
<asp:Label ID="Exchange" runat="server" Text='<%# Eval("Exchange")=="True" ? "True": "" %></asp:Label>'
The DataReader["Exchange"].ToString() itself will return a string "True" or "False" hence you dont need to use any condition for this:
<asp:Label ID=\"Exchange\" runat=\"server\" Text=\"<%#Eval("Exchange").ToString()%>\" </asp:Label>
I have a few fields that look like this in a website that uses ASP and VB (the data is displayed in a gridview):
<asp:TemplateField HeaderText ="Comp" SortExpression="NAM_CMPT" ItemStyle-Width="50%" ItemStyle-Wrap ="false" ItemStyle-HorizontalAlign ="left">
<ItemTemplate>
<asp:Label ID ="Label_Comp" runat="server"
Text='<%# Eval("CDE_CMPT") + " - " + Eval("NAM_CMPT")%>' />
</ItemTemplate>
</asp:TemplateField>
And what I'm trying to do is display nothing in the field if the data is empty, and display the string you see in the Text property if there is data. Currently it displays the hyphen used in the Text string when there is no data. I tried several methods of formatting the Eval that I found online but was unable to find a working solution. I also tried using the
EmptyDataText
property however this seemed to have no effect.
I am new to ASP so that could be user error. Any help is greatly appreciated.
You can also use eval for visible and check for data
<asp:TemplateField HeaderText ="Comp" SortExpression="NAM_CMPT" ItemStyle-Width="50%" ItemStyle-Wrap ="false" ItemStyle-HorizontalAlign ="left">
<ItemTemplate>
<asp:Label ID ="Label_Comp" runat="server" visible='<%# If(String.IsNullOrEmpty(Eval("CDE_CMPT")), false, true)'
Text='<%# Eval("CDE_CMPT") + " - " + Eval("NAM_CMPT")%>' />
</ItemTemplate>
</asp:TemplateField>
I haven't used VB.net is a while, so the syntax might be off.
I have a TemplateField column in a gridview with a image button inside of it.
i need to use two command arguments within single image button.
here is my code
<asp:TemplateField ItemStyle-Width="30px">
<ItemTemplate>
<asp:ImageButton ID="btnAvaililabitly" runat="server"
ImageUrl="~/CMS/images/available_icon.png"
Width="12px" Height="12px" CommandName="availability"
ToolTip="Rooms Availability"
CommandArgument='<%#Eval("HotelID")%>'/>
</ItemTemplate>
</asp:TemplateField>
please help
You can send comma separated string and collect value on server side
CommandArgument= '<%# String.Format("{0} , {1}", Eval("Name1"), Eval("Name2")) %>'