[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

c# syntax on a ASP.Net page

Posted on 2013-01-29
33
Medium Priority
?
831 Views
Last Modified: 2013-02-04
I have a datagrid that I and using a nested View template using Telerik But what I want to do is just do a simple If then based on the data in the GIS field.

Cannot implicitly convert object to Bool.  and then another error on the %> closing saying expected class.

I'm new to C# so just heed a little help here I think


 
<%# if (DataBinder.Eval(Container.DataItem,"GIS")) = 'yes') 
                                               {
                                                        %>
                                             THIS IS A TEST GIS IS TURNED ON then do something
                                                 <% 
                                                    } 
                                                    
                                                    %>

Open in new window



Here is the WHOLE page for reference


<%@ Page Title="" Language="C#" MasterPageFile="~/MASTER-MAIN.Master" AutoEventWireup="true" CodeBehind="MCDPermitView.aspx.cs" Inherits="MCD_INTRANET.MCDPermitView" %>

<%@ Register Assembly="Telerik.ReportViewer.WebForms, Version=6.2.12.1017, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" Namespace="Telerik.ReportViewer.WebForms" TagPrefix="telerik" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
        .auto-style9
        {
            font-size: large;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <span class="auto-style9"><strong>MCD Permit Search and Report Tool</strong></span><br />
    <br />

    To use this tool, use the filter and sort options under the column headers below. To sort a column just click on the column header(s). Click on the small triangle to expand the report details.
    <br />
    If you want to view, print or download the report, click the "Update report query" button and then scroll down to see the report.<br />
    <br />
    <asp:Button ID="Button1" runat="server" Text="Update report query" PostBackUrl="~/Permits/MCDPermitView.aspx" />

    <asp:Button ID="Button2" runat="server" Text="Load Report" PostBackUrl="~/Permits/MCDPermitView.aspx" OnClick="Button2_Click" />
    <br />
    <asp:Label ID="MESSAGElbl" runat="server" Text="DEFAULT TEXT IS HERE"></asp:Label>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:PermitsConnectionString %>" SelectCommand="SELECT     vPERMITS.MCDNUM, vPERMITS.ISSUEDTO, vPERMITS.DATEISSUED, vPERMITS.LOCATION + ' --- ' + vPERMITS.FEATURE AS LOCATION, vPERMITS.PURPOSE,vPERMITS.GIS, 
                      vPERMITS.EXPIREDATE ,  (CAST(THETYPE AS varchar(12)) + ' - ' + DESCRIPTION) as PERMIT, vPERMITS.AUTOID, vPERMITS.STATUS 
FROM         PERMITTYPES RIGHT OUTER JOIN
                      vPERMITS ON PERMITTYPES.PERMITCODE = vPERMITS.THETYPE ORDER BY MCDNUM"></asp:SqlDataSource>

    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:PermitsConnectionString %>" SelectCommand="        SELECT     *
         FROM       vPERMITS 
where AUTOID =@AUTOID">
        <SelectParameters>
            <asp:Parameter DefaultValue="1" Name="AUTOID" />
        </SelectParameters>
    </asp:SqlDataSource>

    <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:PermitsConnectionString %>" SelectCommand="SELECT distinct [STATUS] FROM [vPERMITS] order by STATUS"></asp:SqlDataSource>



    <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" CellSpacing="0" DataSourceID="SqlDataSource1" GridLines="None" Height="700px" PageSize="100" ShowFooter="True" ShowGroupPanel="True" AutoGenerateColumns="False" Style="margin-top: 0px; margin-right: 50px;" OnNeedDataSource="RadGrid1_NeedDataSource" EnableLinqExpressions='False' OnItemCommand="RadGrid1_ItemCommand1">
        <GroupingSettings CaseSensitive="false" />
        <ClientSettings AllowColumnsReorder="True" AllowDragToGroup="True" ReorderColumnsOnClient="True">
            <Selecting AllowRowSelect="True" />
            <Scrolling AllowScroll="True" UseStaticHeaders="True" />
            <Resizing AllowColumnResize="True" AllowResizeToFit="True" AllowRowResize="True" EnableRealTimeResize="True" ResizeGridOnColumnResize="True" />
            <Animation AllowColumnReorderAnimation="True" AllowColumnRevertAnimation="True" />
        </ClientSettings>
        <MasterTableView DataSourceID="SqlDataSource1" DataKeyNames="AUTOID" AllowMultiColumnSorting="True" GroupLoadMode="Server">
            <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>

            <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
                <HeaderStyle Width="20px"></HeaderStyle>
            </RowIndicatorColumn>

            <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
                <HeaderStyle Width="20px"></HeaderStyle>
            </ExpandCollapseColumn>

            <Columns>
                <telerik:GridHyperLinkColumn AllowFiltering="False" AllowSorting="False" DataNavigateUrlFields="AUTOID" DataNavigateUrlFormatString="MCDPermitView.aspx?ID={0}" DataTextField="AUTOID" EditFormHeaderTextFormat="test {0}:" FilterControlAltText="Filter AUTOIDCOLUMN column" HeaderText=" " ImageUrl="/images/Info-Small.png" UniqueName="AUTOIDCOLUMN">

                    <HeaderStyle Width="30px" />

                </telerik:GridHyperLinkColumn>

                <telerik:GridBoundColumn DataField="MCDNUM" DataType="System.Double" FilterControlAltText="Filter MCDNUM column" HeaderText="MCDNUM" SortExpression="MCDNUM" UniqueName="MCDNUM" FilterControlWidth="30px">
                    <HeaderStyle Width="75px" />
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="ISSUEDTO" FilterControlAltText="Filter ISSUEDTO column" HeaderText="ISSUEDTO" SortExpression="ISSUEDTO" UniqueName="ISSUEDTO">
                    <HeaderStyle Width="150px" />
                </telerik:GridBoundColumn>



                <telerik:GridBoundColumn DataField="DATEISSUED" DataType="System.DateTime" FilterControlAltText="Filter DATEISSUED column" HeaderText="DATEISSUED"
                    SortExpression="DATEISSUED" UniqueName="DATEISSUED" DataFormatString="{0:d}" HeaderStyle-Width="350px">
                    <FilterTemplate>
                        From:
                        <telerik:RadDatePicker ID="FromOrderDatePicker" runat="server" Width="100px" ClientEvents-OnDateSelected="FromDateSelectedDateIssued"
                            MinDate="01-01-1918" MaxDate="12-31-2020" FocusedDate="01-01-1970" DbSelectedDate='<%# startDateDateIssue %>' />
                        <br />
                        To: &nbsp;&nbsp;&nbsp;&nbsp;
                        <telerik:RadDatePicker ID="ToOrderDatePicker" runat="server" Width="100px" ClientEvents-OnDateSelected="ToDateSelectedDateIssued"
                            MinDate="01-01-1918" MaxDate="12-31-2020" FocusedDate="12-31-2020" DbSelectedDate='<%# endDateDateIssue %>' />
                        <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
                            <script type="text/javascript">
                                function FromDateSelectedDateIssued(sender, args) {
                                    var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                    var ToPicker = $find('<%# ((GridItem)Container).FindControl("ToOrderDatePicker").ClientID %>');

                                    var fromDate = FormatSelectedDate(sender);
                                    var toDate = FormatSelectedDate(ToPicker);

                                    tableView.filter("DATEISSUED", fromDate + " " + toDate, "Between");

                                }
                                function ToDateSelectedDateIssued(sender, args) {
                                    var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                    var FromPicker = $find('<%# ((GridItem)Container).FindControl("FromOrderDatePicker").ClientID %>');

                                    var fromDate = FormatSelectedDateDateIssued(FromPicker);
                                    var toDate = FormatSelectedDateDateIssued(sender);

                                    tableView.filter("DATEISSUED", fromDate + " " + toDate, "Between");
                                }
                                function FormatSelectedDateDateIssued(picker) {
                                    var date = picker.get_selectedDate();
                                    var dateInput = picker.get_dateInput();
                                    var formattedDate = dateInput.get_dateFormatInfo().FormatDate(date, dateInput.get_displayDateFormat());

                                    return formattedDate;
                                }
                            </script>
                        </telerik:RadScriptBlock>
                    </FilterTemplate>






                    <HeaderStyle Width="148px"></HeaderStyle>






                </telerik:GridBoundColumn>




                <telerik:GridBoundColumn DataField="LOCATION" FilterControlAltText="Filter LOCATION column" HeaderText="LOCATION" ReadOnly="True" SortExpression="LOCATION" UniqueName="LOCATION">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="PURPOSE" FilterControlAltText="Filter PURPOSE column" HeaderText="PURPOSE" SortExpression="PURPOSE" UniqueName="PURPOSE">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="EXPIREDATE" DataType="System.DateTime" FilterControlAltText="Filter EXPIREDATE column" HeaderText="EXPIREDATE" SortExpression="EXPIREDATE" UniqueName="EXPIREDATE" DataFormatString="{0:d}" HeaderStyle-Width="350px">
                    <FilterTemplate>
                        From:
                        <telerik:RadDatePicker ID="FromOrderDatePicker2" runat="server" Width="100px" ClientEvents-OnDateSelected="FromDateSelected"
                            MinDate="01-01-1918" MaxDate="12-31-2020" FocusedDate="01-01-1970" DbSelectedDate='<%# startDateExpireDate %>' />
                        <br />
                        To: &nbsp;&nbsp;&nbsp;&nbsp;
                        <telerik:RadDatePicker ID="ToOrderDatePicker2" runat="server" Width="100px" ClientEvents-OnDateSelected="ToDateSelected"
                            MinDate="01-01-1918" MaxDate="12-31-2020" FocusedDate="12-31-2020" DbSelectedDate='<%# endDateExpireDate %>' />
                        <telerik:RadScriptBlock ID="RadScriptBlock2" runat="server">
                            <script type="text/javascript">
                                function FromDateSelected(sender, args) {
                                    var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                    var ToPicker = $find('<%# ((GridItem)Container).FindControl("ToOrderDatePicker2").ClientID %>');

                                    var fromDate = FormatSelectedDate(sender);
                                    var toDate = FormatSelectedDate(ToPicker);

                                    tableView.filter("EXPIREDATE", fromDate + " " + toDate, "Between");

                                }
                                function ToDateSelected(sender, args) {
                                    var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                    var FromPicker = $find('<%# ((GridItem)Container).FindControl("FromOrderDatePicker2").ClientID %>');

                                    var fromDate = FormatSelectedDate(FromPicker);
                                    var toDate = FormatSelectedDate(sender);

                                    tableView.filter("EXPIREDATE", fromDate + " " + toDate, "Between");
                                }
                                function FormatSelectedDate(picker) {
                                    var date = picker.get_selectedDate();
                                    var dateInput = picker.get_dateInput();
                                    var formattedDate = dateInput.get_dateFormatInfo().FormatDate(date, dateInput.get_displayDateFormat());

                                    return formattedDate;
                                }
                            </script>
                        </telerik:RadScriptBlock>
                    </FilterTemplate>
                    <HeaderStyle Width="148px"></HeaderStyle>
                </telerik:GridBoundColumn>

                <telerik:GridBoundColumn DataField="PERMIT" FilterControlAltText="Filter PERMIT column" HeaderText="PERMIT" SortExpression="PERMIT" UniqueName="PERMIT" ReadOnly="True">
                </telerik:GridBoundColumn>

                <telerik:GridBoundColumn DataField="AUTOID" DataType="System.Int32" Display="False" FilterControlAltText="Filter AUTOID column" HeaderText="AUTOID" ReadOnly="True" UniqueName="AUTOID">
                </telerik:GridBoundColumn>

                <telerik:GridBoundColumn UniqueName="STATUS" DataField="STATUS" FilterControlAltText="Filter column column" HeaderText="STATUS">


                   <FilterTemplate>
                        <telerik:RadComboBox ID="RadComboBoxTitle" DataSourceID="SqlDataSource3" DataTextField="STATUS"
                            DataValueField="STATUS" Height="200px" AppendDataBoundItems="true" SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("STATUS").CurrentFilterValue %>'
                            runat="server" OnClientSelectedIndexChanged="TitleIndexChanged">
                            <Items>
                                <telerik:RadComboBoxItem Text="All" />
                            </Items>
                        </telerik:RadComboBox>
                        <telerik:RadScriptBlock ID="RadScriptBlock10" runat="server">
                            <script type="text/javascript">
                                function TitleIndexChanged(sender, args) {
                                    var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                    tableView.filter("STATUS", args.get_item().get_value(), "EqualTo");

                                }
                            </script>
                        </telerik:RadScriptBlock>
                    </FilterTemplate> 

                  


                </telerik:GridBoundColumn>

                <telerik:GridBoundColumn DataField="GIS" Display="False" FilterControlAltText="Filter GIS column" HeaderText="GIS" ReadOnly="True" UniqueName="GIS" Visible="False">
                </telerik:GridBoundColumn>

            </Columns>

            <EditFormSettings>
                <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
            </EditFormSettings>



            <NestedViewSettings DataSourceID="SqlDataSource2">
                <ParentTableRelation>
                    <telerik:GridRelationFields DetailKeyField="AUTOID" MasterKeyField="AUTOID" />
                </ParentTableRelation>
            </NestedViewSettings>
            <NestedViewTemplate>
                <asp:Panel ID="NestedViewPanel" runat="server" CssClass="viewWrap">
                    <div class="contactWrap">
                        <fieldset style="padding: 10px;">
                            <legend style="padding: 5px;"><b>Details for Permit#:&nbsp; &nbsp;<%#Eval("MCDNUM") %></b></legend>
                            <table>
                                <tbody>
                                    <tr>
                                        <td>
                                            <table>
                                                <tbody>
                                                    <tr>
                                                        <td>Status:
                                                        </td>
                                                        <td>
                                                            <asp:Label ID="cityLabel" Text='<%#Bind("STATUS") %>' runat="server"></asp:Label>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>Drawing Number:
                                                        </td>
                                                        <td>
                                                            <asp:Label ID="Label2" Text='<%#Bind("DRAWINGNO") %>' runat="server"></asp:Label>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>Scanned?:
                                                        </td>
                                                        <td>
                                                            <asp:Label ID="Label3" Text='<%#Bind("SCANNED") %>' runat="server"></asp:Label>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>Contact:
                                                        </td>
                                                        <td>
                                                            <asp:Label ID="Label4" Text='<%#Bind("CONTACT") %>' runat="server"></asp:Label>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>Phone:
                                                        </td>
                                                        <td>
                                                            <asp:Label ID="Label5" Text='<%#Bind("PHONE") %>' runat="server"></asp:Label>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>Drawing Number:
                                                        </td>
                                                        <td>
                                                            <asp:Label ID="Label6" Text='<%#Bind("DRAWINGNO") %>' runat="server"></asp:Label>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>Board:
                                                        </td>
                                                        <td>
                                                            <asp:Label ID="Label7" Text='<%#Bind("BOARD") %>' runat="server"></asp:Label>
                                                        </td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                        <td>
                                            <img src='<%# Page.ResolveUrl("/images/Info-Small.png?test=") + Eval("AUTOID") %>.jpg'
                                                alt="Customer Image" />

                                            <%# if (DataBinder.Eval(Container.DataItem,"GIS")) = 'yes') 
                                               {
                                                        %>
                                             THIS IS A TEST GIS IS NOT NULL
                                                 <% 
                                                    } 
                                                    
                                                    %>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </fieldset>
                    </div>
                </asp:Panel>
            </NestedViewTemplate>







        </MasterTableView>

        <FilterMenu EnableImageSprites="False"></FilterMenu>
    </telerik:RadGrid>



    <strong>Report based on the selection above</strong><br />
    <br />



    <telerik:ReportViewer ID="ReportViewer2" runat="server" Width="97%" Height="700px" Style="margin-top: 0px; margin-right: 50px;">

            <typereportsource typename="MCD_INTRANET.PermitReport2, MCD INTRANET, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"></typereportsource>

    </telerik:ReportViewer>




</asp:Content>

Open in new window

0
Comment
Question by:Jason Jones
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 19
  • 13
33 Comments
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 38831329
change it to:

<%# if (DataBinder.Eval(Container.DataItem,"GIS")) == 'yes') 
                                               {
                                                        %>
                                             THIS IS A TEST GIS IS TURNED ON then do something
                                                 <% 
                                                    } 
                                                    
                                                    %>

Open in new window

0
 
LVL 15

Expert Comment

by:santhimurthyd
ID: 38831364
Check it whether it helps out

<%# if (Convert.ToString(Eval("GIS")).Equals("yes")) { %>

 THIS IS A TEST GIS IS TURNED ON then do something
<%
      }

%>
0
 
LVL 1

Author Comment

by:Jason Jones
ID: 38832856
Thanks both of you, I am out of the office and will check the solution suggestions in the morning.  about 14 hours from now.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:Jason Jones
ID: 38834832
Hi sedgwick, your code gave this compile error

Line 300:                                                alt="Customer Image" />
Line 301:
Line 302:                                           <%# if (DataBinder.Eval(Container.DataItem,"GIS")) == 'yes')
Line 303:                                               {
Line 304:                                                        %>








santhimurthyd yours gave me this error


CS1518: Expected class, delegate, enum, interface, or struct

Source Error:


Line 43:
Line 44:
Line 45:     <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" CellSpacing="0" DataSourceID="SqlDataSource1" GridLines="None" Height="700px" PageSize="100" ShowFooter="True" ShowGroupPanel="True" AutoGenerateColumns="False" Style="margin-top: 0px; margin-right: 50px;" OnNeedDataSource="RadGrid1_NeedDataSource" EnableLinqExpressions='False' OnItemCommand="RadGrid1_ItemCommand1">
Line 46:         <GroupingSettings CaseSensitive="false" />
Line 47:         <ClientSettings AllowColumnsReorder="True" AllowDragToGroup="True" ReorderColumnsOnClient="True">
0
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 38834839
here:

   <%# if (DataBinder.Eval(Container.DataItem,"GIS").ToString() == 'yes') 

Open in new window

0
 
LVL 1

Author Comment

by:Jason Jones
ID: 38834850
sedgwick,  sorry I didn't get all of the debug info for you.

The "if" says Invalid expression term if


(DataBinder.Eval(Container.DataItem,"GIS")) says Cannot implicitly convert object to Bool

== says invalid term

and 'yes') says too many characters


Does this have something to do with expressions since we are using the <%# ?
0
 
LVL 1

Author Comment

by:Jason Jones
ID: 38834864
the last one says Operator '==' cannot be applied to operands of type 'string'
 and 'char'   and the "if" still says invalid expression
0
 
LVL 1

Author Comment

by:Jason Jones
ID: 38834929
this is defiantly because of the <%#  this is defining an expression in the Grid control and although I think it could work for some basic if then I don't think the expression way is going to work because ultimately I am trying to either show a link or not depending if GIS is "yes"

So I took the  # off and  on this line if (DataBinder.Eval(Container.DataItem,"GIS").ToString() == 'yes')  and it says "The name Container" is not part of the current context" and 'yes') says too many characters in character literal

In  santhimurthyd code if I remove the # the error is different it says "Databinding methods such as Eval() Xpath() and Bind() can only be used in the context of a databound control

so is there any way I can accomplish my task?
0
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 38834979
what do u want to display in case DataBinder.Eval(Container.DataItem,"GIS") == yes ?
0
 
LVL 1

Author Comment

by:Jason Jones
ID: 38835033
A URL link to another page with the ID of that record.  so for example

www.mylink.com/thePage.aspx?id=1234
0
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 38835043
and if not equal to yes?
0
 
LVL 1

Author Comment

by:Jason Jones
ID: 38835050
then show nothing or perhaps later an image that says "no GIS layer" or some feedback
0
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 38835079
add the link inside your aspx page and use the DataBinder.Eval to set the visible attribute of the url:

<a href="www.mylink.com/thePage.aspx?id=1234" Visible='<%# DataBinder.Eval("GIS").ToString() == 'yes' %>'>Next Page</a>

Open in new window

0
 
LVL 1

Author Comment

by:Jason Jones
ID: 38835164
I get the error

DataBinder.Eval("GIS")

: CS1012: Too many characters in character literal

and 'yes'
: says too many characters in character literal
0
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 38835181
<a href="www.mylink.com/thePage.aspx?id=1234" Visible='<%# DataBinder.Eval(Container.DataItem, "GIS").ToString() == 'yes' %>'>Next Page</a>

Open in new window

0
 
LVL 1

Author Comment

by:Jason Jones
ID: 38835488
Thanks for the continued help..  unfortunately that is also giving the error when compiled

CS1012: Too many characters in character literal

in Visual Studio it has the whole line giving the error

"Operator == cannot be applied to operands of type string and char
0
 
LVL 42

Accepted Solution

by:
Meir Rivkin earned 2000 total points
ID: 38835574
sorry my bad:
<a href="www.mylink.com/thePage.aspx?id=1234" Visible='<%# DataBinder.Eval(Container.DataItem, "GIS").ToString() == "yes" %>'>Next Page</a>

Open in new window

0
 
LVL 1

Author Comment

by:Jason Jones
ID: 38835616
Great it works!  thanks  if I need to make two conditions true for the "yes" to be generated is that possible.. for example  GIS = "yes" and PropertyType = "line" is that possible?
0
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 38835647
<a href="www.mylink.com/thePage.aspx?id=1234" Visible='<%# DataBinder.Eval(Container.DataItem, "GIS").ToString() == "yes" && DataBinder.Eval(Container.DataItem, "PropertyType").ToString() == "line"%>'>Next Page</a>

Open in new window

0
 
LVL 1

Author Comment

by:Jason Jones
ID: 38835670
Thanks again Sedgwick, I'll have to test that one as soon as our new field is in the database. So should I assume that there is no way of pulling the data to do an "if then" outside of the expression like I was initially trying to do?
0
 
LVL 1

Author Comment

by:Jason Jones
ID: 38845014
I may have spoke too soon as this being the solution.  I have noticed that where there are field values that do not have GIS = yes such as GIS = no or is null it does not matter what the data item is,  the Visible attribute is always Yes...  there is no " If then" logic working.  I realized I awarded points already, but hope that you can review this.
0
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 38845301
Thats weird let me check it again
0
 
LVL 1

Author Comment

by:Jason Jones
ID: 38850831
were you able to look at this?
0
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 38850840
change it to this:
<a href="www.mylink.com/thePage.aspx?id=1234" Visible='<%# 
DataBinder.Eval(Container.DataItem, "GIS") != null ? (DataBinder.Eval(Container.DataItem, "GIS").ToString() == "yes" && DataBinder.Eval(Container.DataItem, "PropertyType").ToString() == "line") : false%>'>Next Page</a>

Open in new window

0
 
LVL 1

Author Comment

by:Jason Jones
ID: 38850975
Sorry that one errored

 DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'PropertyType'.
0
 
LVL 1

Author Comment

by:Jason Jones
ID: 38851276
Although the last suggestion does not work, After some more detective work, and although your first example it works ID: 38835574 and makes the code behind write visible ='True' or False based on the GIS field, however what is happening is that the "Visible" is not behaving.  It says True or False in the page source.  So I tried lowercase visible and it is still not working. So even if the last suggestion would work, the visible property of the page is not behaving.  Boy what a pain in ASP script I could do this and be done with it in a simple 3 line "If then"
0
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 38851303
the last error with PropertyType, indicate that the row doesn't have a field called PropertyType. can make sure of that?
0
 
LVL 1

Author Comment

by:Jason Jones
ID: 38851316
That is correct I do not have a field called PropertyType. Sorry  I thought it was added on my version of our code, but wasn't.  So my problem is still the link visibility issue. Your code is working in the way you intended, but the link is not being hidden if GIS is not equal to 'yes'
0
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 38851329
just for testing try this:

<a href="www.mylink.com/thePage.aspx?id=1234" Visible='<%# 1 == 0 %>'>Next Page</a>

Open in new window

0
 
LVL 1

Author Comment

by:Jason Jones
ID: 38851426
it shows the link... in the page source it says
 <a href="www.mylink.com/thePage.aspx?id=1234" Visible='False'>Next Page2</a>



I figured I would try CSS and use the style visibility and my hard coded test works so I figured I would try a variation of your code

 <a  style="visibility:<%# System.Convert.ToBoolean((DataBinder.Eval(Container.DataItem, "GIS").ToString() =="yes") ? "true":"false") %>" href='http://intranet.domain.org/GISPermit/MCDpermitLocator.html?mcdnum=<%# Eval("MCDNUM") %>&GIS=<%# Eval("GIS") %>' target='_blank'>Go to GIS Map!</a>

The true and false work so I figured I would then try to change them to the proper variables

 <a  style="visibility:<%# System.Convert.ToBoolean((DataBinder.Eval(Container.DataItem, "GIS").ToString() =="yes") ? "visible":"hidden") %>" href='http://intranet.domain.org/GISPermit/MCDpermitLocator.html?mcdnum=<%# Eval("MCDNUM") %>&GIS=<%# Eval("GIS") %>' target='_blank'>Go to GIS Map!</a>

Same exact code except the visible and hidden changed...  and I get an odd error

String was not recognized as a valid Boolean.

if I can get this one to work I think I am done..
0
 
LVL 1

Author Comment

by:Jason Jones
ID: 38851444
DUH...  I removed the System.Convert.ToBoolean and it works!!!!!


                                       <a  style="visibility:<%# ((DataBinder.Eval(Container.DataItem, "GIS").ToString() =="yes") ? "visible":"hidden") %>" href='http://intranet.domain.org/GISPermit/MCDpermitLocator.html?mcdnum=<%# Eval("MCDNUM") %>&GIS=<%# Eval("GIS") %>' target='_blank'>Go to GIS Map!</a>
0
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 38851457
jesus christ ;-|
i've missed the System.Convert.ToBoolean code, sorry
0
 
LVL 1

Author Comment

by:Jason Jones
ID: 38851484
no big deal..  I'm still learning all this so for a newbie like me this is a good learning experience!..  I can't find anywhere the people c# syntax for expressions in a Grid so most of my tests were copy, paste, change and test...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question