Solved

c# syntax on a ASP.Net page

Posted on 2013-01-29
33
767 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:upgraders
  • 19
  • 13
33 Comments
 
LVL 42

Expert Comment

by:sedgwick
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:upgraders
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
 
LVL 1

Author Comment

by:upgraders
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:sedgwick
ID: 38834839
here:

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

Open in new window

0
 
LVL 1

Author Comment

by:upgraders
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:upgraders
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:upgraders
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:sedgwick
ID: 38834979
what do u want to display in case DataBinder.Eval(Container.DataItem,"GIS") == yes ?
0
 
LVL 1

Author Comment

by:upgraders
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:sedgwick
ID: 38835043
and if not equal to yes?
0
 
LVL 1

Author Comment

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

Expert Comment

by:sedgwick
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:upgraders
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:sedgwick
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:upgraders
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 42

Accepted Solution

by:
sedgwick earned 500 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:upgraders
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:sedgwick
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:upgraders
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:upgraders
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:sedgwick
ID: 38845301
Thats weird let me check it again
0
 
LVL 1

Author Comment

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

Expert Comment

by:sedgwick
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:upgraders
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:upgraders
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:sedgwick
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:upgraders
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:sedgwick
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:upgraders
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:upgraders
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:sedgwick
ID: 38851457
jesus christ ;-|
i've missed the System.Convert.ToBoolean code, sorry
0
 
LVL 1

Author Comment

by:upgraders
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now