Eval function for checkbox - c#

This is my html code inside the gridview.. I want to add "OR" condition in Eval function..
how can i do?
<asp:TemplateField HeaderText="Report" HeaderStyle-CssClass="headerfont">
<ItemTemplate>
<asp:CheckBox ID="checkReport" runat="server" Checked='<%# bool.Parse(Eval("rm_rights").ToString() == "1R" ? "True": "False") %>'
Enabled="true" AutoPostBack="True" />
</ItemTemplate>
<HeaderStyle CssClass="headerfont"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
i need code like this
`Checked='<%# bool.Parse(Eval("rm_rights").ToString() == "2R" ? "True": "False") %>'`
OR operator
Checked='<%# bool.Parse(Eval("rm_rights").ToString() == "3R" ? "True": "False") %>'

you are using bool function and u evaluate this expression with 1R so it gives u error .
remove bool.parse function and check again

Try this , You have misplaced the bracket ,<%# ... %> block supports conditional operator, eval is a different function
" <%# Eval("rm_rights").ToString() == "1R" ? "True": "False" %>"

Related

How to conditionally generate html in ASP template

I'm a total newbie to this. How do I conditionally wrap this <Colosseum:PersonLabel... with <strong></strong>
<asp:TemplateColumn
HeaderText="Member"
ItemStyle-Wrap="false"
SortExpression="leader_name">
<ItemTemplate>
<Colosseum:PersonLabel ID="plPerson" runat="server"
PersonGUID='<%# Eval("person_guid") %>'
PersonName='<%# Eval("person_name") %>'
HasPhoto='<%# Eval("person_blob_id") != DBNull.Value %>'
Restricted='<%# Eval("restricted") != DBNull.Value && Convert.ToBoolean(Eval("restricted")) %>'
/>
</ItemTemplate>
</asp:TemplateColumn>
For example:
Font-Bold='<%# Eval("FeedName").ToString().Contains("Band") %>'
It works essentially like the other expressions you have on the label.
// true if `person_blob_id` is not null.
HasPhoto='<%# Eval("person_blob_id") != DBNull.Value %>'

Set the values to Null if its a 0 on Data Grid asp.net

I have a Data grid that has Item Templates with Labels in it:
<asp:datagrid id="ID" runat="server" Width="641px" CellPadding="2" PageSize="2" DataKeyField="IDs"
AutoGenerateColumns="False" ShowFooter="True" BorderColor="AliceBlue" OnItemDataBound="ID_ItemDataBound" >
<SelectedItemStyle ForeColor="HighlightText" BackColor="Highlight"> </SelectedItemStyle>
<AlternatingItemStyle BackColor="WhiteSmoke">
</AlternatingItemStyle>
<HeaderStyle Font-Bold="True" BackColor="AliceBlue">
</HeaderStyle>
<FooterStyle Font-Bold="True" BackColor="AliceBlue">
</FooterStyle>
<Columns>
<ItemTemplate>
<asp:label BorderStyle=None Visible='<%# ReverseBool(Convert.ToBoolean(DataBinder.Eval(Container, "DataItem.IsCompleteOrNot"))) %>' runat="server" ID="dataScore" Text='<%# DataBinder.Eval(Container, "DataItem.dataScore" ) %>'>
</asp:label>
<asp:label BorderStyle=None Text='<%# GetCompleteIncomplete(Convert.ToInt32(DataBinder.Eval(Container, "DataItem.dataScore")!=null)) %>' Visible='<%# DataBinder.Eval(Container, "DataItem.IsCompleteOrNot") %>' id="txtIsComplete" runat="server">
</asp:label>
</ItemTemplate>
</columns>
And I am trying to Set the 0s to blank instead of showing 0 in the DataGrid so on ItemData bound I get the Label like this and trying to set the value to null:
if ((e.Item.ItemType == ListItemType.Item) ||
(e.Item.ItemType == ListItemType.AlternatingItem))
{
Label dataScore = (Label)e.Item.FindControl("dataScore"); // Gets that Label
Label txtIsComplete = (Label)e.Item.FindControl("txtIsComplete");
if(dataScore .Text == "0")
{
dataScore.Text = string.Empty; // Tried
}
You can write a function to analyse the value of DataBinder.Eval
Private String MyFunction(String value)
{
Return value == "0" ? String.Empty : value;
}
<asp:label BorderStyle=None Visible='<%# ReverseBool(Convert.ToBoolean(DataBinder.Eval(Container, "DataItem.IsCompleteOrNot"))) %>' runat="server" ID="dataScore" Text='<%# MyFunction(DataBinder.Eval(Container, "DataItem.dataScore" )) %>'>

how can set a color to a row of gridview when link button is clicked

I have a gridview in my page. grid has one linkbutton. how can set a color to a row of gridview when linkbutton is clicked?
<asp:TemplateField ItemStyle-Width="20%" HeaderText="Options" HeaderStyle-CssClass="headerfont">
<ItemTemplate>
<div class="headerfontnew">
<asp:CheckBox ID="checkView" runat="server" Checked='<%# bool.Parse(Eval("rm_rights").ToString() == "1" ? "True": "False") %>' Enabled="true" onclick="CheckBoxCheck(this);"/>
<asp:CheckBox ID="checkInsert" runat="server" Checked='<%# bool.Parse(Eval("rm_rights").ToString() == "2" ? "True": "False") %>' Enabled="true" onclick="CheckBoxCheck(this);" />
<asp:CheckBox ID="checkUpdate" runat="server" Checked='<%# bool.Parse(Eval("rm_rights").ToString() == "3" ? "True": "False") %>' Enabled="true" onclick="CheckBoxCheck(this);"/>
<asp:CheckBox ID="checkDelete" runat="server" Checked='<%# bool.Parse(Eval("rm_rights").ToString() == "4" ? "True": "False") %>' Enabled="true" onclick="CheckBoxCheck(this);"/>
<asp:LinkButton ID="LinkButton1" CommandName="Child" CommandArgument='<%#Eval("menu_id")%>' runat="server" >
<img id="ChildMenu" src="images/image_viewer.png" class="Gridimage" title="View Childs" runat="server" ></img></asp:LinkButton>
</div>
</ItemTemplate>
<HeaderStyle CssClass="headerfont"></HeaderStyle>
<ItemStyle></ItemStyle>
</asp:TemplateField>
if the link is inside a td, get to the row (parent) and change its color, something like this
$('#linkbutton').parent().css('background-color', '#F00');
You have two ways to do it:
1) On the server in code-behind. In the click event of the button, assuming the index of the row that you want to set its color is 5, and you want to set it to red:
void LinkButton_Click(Object sender, EventArgs e)
{
myGrid.Rows[5].BackColor = System.Drawing.Color.Red;
}
2) On the user's computer (i.e. client-side) using JavaScript. You need to access the row using its id, so use its ClientID property:
<asp:LinkButton ........ OnClientClick="HighlightRow()" />
<script>
function HighlightRow() {
document.getElementById("<%=myGrid.Rows[5].ClientID%>").style.background = "red";
}
</script>

Display particular word on some condition Eval Asp.net

<asp:Label ID="lblLeaveStatus" runat="server" Font-Bold="true" Text='<%# Eval("Leave_Status").ToString() == 'A' ? 'Approved' : 'Applied' %>'></asp:Label>
Condition to display a particular word in the GridView on some condition
Could some thing like this work on Gridview
I get an error Server Tag not well formed
Try this
<asp:Label ID="lblLeaveStatus" runat="server" Font-Bold="true" Text='<%# Eval("Leave_Status").ToString() .Equals ( "A") ? "Approved" : "Applied" %>'></asp:Label>
Use Below Code:
<% if(Eval("Leave_Status").ToString() == "A"{%>
<asp:Label ID="lblLeaveStatus" runat="server" Font-Bold="true" Text="Approved"></asp:Label>
<%}
else {
%>
<asp:Label ID="lblLeaveStatus" runat="server" Font-Bold="true" Text="Applied"></asp:Label>
<%}%>

hide gridview hyperlink in visible property of source rather then code behind

Ive got a gridview with an itemtemplate that has a hyperlink control in it. I want to hide a hyperlink control if its item in the database returned null:
<ItemTemplate>
<asp:HyperLink ID="hlSugar" Visible=<% DataBinder.Eval(Container, "DataItem.CaseID")==null %> ToolTip="View the issue in SugarCRM." Target="_blank" runat="server" NavigateUrl='<%# "http://myPath&record=" + DataBinder.Eval(Container, "DataItem.CaseID") %>' Text="Issue"></asp:HyperLink>
</ItemTemplate>
Not sure on the syntax can I do
Visible = <% iif(databinder.eval(container, "dataItem.caseid")==null, false, true) %>
Not sure how to get the syntax correct. I basically want to check if my `DataItem.CaseID is null and hide this field if it is.
I ended up using this:
Visible='<%# Eval("SugarCaseID") != DBNull.Value %>'
visible='<%# Eval("dataItem.caseid") != null) %>'
Give this a shot
You can do this
bool ShowLink(obj data)
{
if(data!=null) {return true; } return false;
}
aspx:
<asp:HyperLink ID="hlSugar" Visible='<%# ShowLink(Eval("CaseID"))%>'
ToolTip="View the issue in SugarCRM." Target="_blank" runat="server"
NavigateUrl='<%# "http://myPath&record="
+ DataBinder.Eval(Container, "DataItem.CaseID") %>' Text="Issue">
</asp:HyperLink>
Use this
<asp:HyperLink ID="hlSugar" Visible='<%# Convert.ToBoolean(Eval("DataItem.CaseID").ToString() == "0") %>' ToolTip="View the issue in SugarCRM." Target="_blank" runat="server" NavigateUrl='<%# "http://myPath&record=" + DataBinder.Eval(Container, "DataItem.CaseID") %>' Text="Issue" />
REference:
Conditions within .aspx file for ListView ItemTemplate

Categories

Resources