Gridview HyperlinkField Help needed

I have a database table...  Primary Key is a combination of ID and Date (DateTime format).  

I am trying to call a separate page to show all Details using a QueryString to send the ID and Date keys, with their values.

Date Field format is "2014-10-07 09:31:17.000" and doesn't get sent properly via the querystring.  ID works fine, no spaces.  

I can only assume that Date with embedded special characters ( space and blank ) cause it to not work.  Doesn't even build the HREF portion of the anchor tag in HTML, but all other parts (colors, target, etc) are done properly!

How can I URLEncode this field in ASPX file to work.  I tried HTTP.Utility.UrlEncode, and other attempts to no avail?

Ideas?
LVL 5
Bob BenderAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HainKurtSr. System AnalystCommented:
use escape

please post some code... how you put it into link, and how you retrieve and use it...
0
Bob BenderAuthor Commented:
Here is the aspx code...   nothing really done in CS file, because no need for this function (or so I think)

   <asp:GridView ID="AdminGridViewNew" runat="server"
        AutoGenerateColumns="False"
        AutoGenerateEditButton="True"
        AutoGenerateSelectButton="True"
        AllowPaging="True"
        CellPadding="5"
        CellSpacing="3"
        DataKeyNames="RequestID,RequestDate"
        DataSourceID="SqlDataSource1"
        HeaderStyle-HorizontalAlign="Center"
        HeaderStyle-Wrap="True"
        HorizontalAlign="Center"
        OnRowUpdating="AdminGridViewNew_RowUpdating"
        OnRowDataBound="AdminGridViewNew_RowDataBound"
        OnSelectedIndexChanged="AdminGridViewNew_SelectedIndexChanged"
        SelectedRowStyle-BackColor="Wheat"
        BackColor="#DEBA84"
        BorderColor="#DEBA84"
        BorderStyle="None"
        BorderWidth="1px">
        <Columns>
            <asp:BoundField DataField="RequestID" HeaderText="Requestor ID" ReadOnly="True" />
            <asp:BoundField DataField="RequestDate" DataFormatString="{0:u}" HeaderText="Request Date" ReadOnly="True" />
            <asp:BoundField DataField="SubmittedBy" HeaderText="Submitted By" ReadOnly="True" />
            <asp:BoundField DataField="AppName" HeaderText="App Name" ReadOnly="True" />
            <asp:BoundField DataField="AppVendor" HeaderText="App Vendor" ReadOnly="True" />
            <asp:TemplateField HeaderText="Status">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server"
                        SelectedValue='<%# Bind("Status") %>'>
                        <asp:ListItem Text="New" Value="New">New</asp:ListItem>
                        <asp:ListItem Text="Complete" Value="Complete">Complete</asp:ListItem>
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("Status") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>

            <asp:HyperLinkField Text="Details..." Target="_blank"
                ControlStyle-BackColor="#FFF7E7"
                ControlStyle-ForeColor="#8C4510"
                DataNavigateUrlFields="RequestID,RequestDate"
                DataNavigateUrlFormatString="ems_NewAppRequest_Details.aspx?ReqKey1={0}&amp;ReqKey2={1}" >
                <ControlStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
            </asp:HyperLinkField>

			</Columns>
        <EmptyDataTemplate>
            <div class="subpage_text1" style="margin: 25px 0px 25px 0px">No Records Available</div>
        </EmptyDataTemplate>
        <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
        <HeaderStyle HorizontalAlign="Center" Wrap="True" BackColor="#A55129" Font-Bold="True" ForeColor="White"></HeaderStyle>
        <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
        <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
        <SelectedRowStyle BackColor="#738A9C" ForeColor="White"></SelectedRowStyle>
    </asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
    OnSelected="AdminDataSource_Selected"
    ConnectionString="<%$ ConnectionStrings:digitallifeConnectionString %>"
    SelectCommand="SELECT [RequestID], [RequestDate], [AppName], [AppVendor], [Status], [StatusUpdated], [StatusUpdatedBy], [SubmittedBy] FROM [ems_NewAppRequest] WHERE ([Status] = 'New') ORDER BY [RequestDate] DESC, [Status]"
    UpdateCommand="UPDATE [ems_NewAppRequest] SET [Status] = @Status, [StatusUpdated] = GETDATE(), [StatusUpdatedBy] = @Status_UpdatedBy WHERE [RequestID] = @RequestID AND [RequestDate] = @RequestDate">
    <UpdateParameters>
        <asp:Parameter Name="Status" Type="String" />
        <asp:Parameter Name="Status_Updated" Type="DateTime" />
        <asp:ControlParameter Name="Status_UpdatedBy" Type="String" ControlID="savedSubmittedBy" PropertyName="text" />
        <asp:Parameter Name="RequestID" Type="String" />
        <asp:Parameter Name="RequestDate" Type="DateTime" />
    </UpdateParameters>
</asp:SqlDataSource>

Open in new window

0
HainKurtSr. System AnalystCommented:
what happens if you just use KISS, line 40-46:

<a  class="aDetail" target="_blank" href='ems_NewAppRequest_Details.aspx?ReqKey1=<%# Bind("RequestID") %>&ReqKey2=<%# Bind("RequestDate") %>'>Details...</a>

or

<a class="aDetail" target="_blank" href='ems_NewAppRequest_Details.aspx?ReqKey1=<%# Eval("RequestID") %>&ReqKey2=<%# HTTP.Utility.UrlEncode(Eval("RequestDate")) %>'>Details...</a>

not sure which one is correct bind/eval, try & figure it out...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

HainKurtSr. System AnalystCommented:
here another approach...

change your query and add this to your select

cast(RequestDate as float) as RequestDateFloat

then use this new field

DataNavigateUrlFields="RequestID,RequestDate"
DataNavigateUrlFormatString="ems_NewAppRequest_Details.aspx?ReqKey1={0}&amp;ReqKey2={1}"

>>>

DataNavigateUrlFields="RequestID,RequestDateFloat"
DataNavigateUrlFormatString="ems_NewAppRequest_Details.aspx?ReqKey1={0}&amp;ReqKey2={1}"

then in your ems_NewAppRequest_Details.aspx, change your query to convert it back to datetime

select ... from ... where ReqKey2 = @ReqKey2
>>>
select ... from ... where ReqKey2 = cast(@ReqKey2 as datetime)
0
HainKurtSr. System AnalystCommented:
and here is another approach

use this:

<script>
function OpenDetails(ReqKey1, ReqKey2){ 
  window.open("OpenDetailsems_NewAppRequest_Details.aspx?ReqKey1=" + ReqKey1 + "&ReqKey2=" + Escape(ReqKey2), "_blank");
}
<script>

<a class="aDetail" target="_blank" href='#' OnClick='OpenDetail("<%# Eval("RequestID") %>","<%# Eval("RequestDate") %>");'>Details...</a>

Open in new window

0
HainKurtSr. System AnalystCommented:
still another approach similar to above... we can create a form and put values inside hidden vars and submit it to blank window... in OpenDetailsems_NewAppRequest_Details.aspx, we may change code like

ReqKey1 = Request.QueryString("ReqKey1")
ReqKey2 = Request.QueryString("ReqKey2")
>>>
ReqKey1 = Request.Form("ReqKey1")
ReqKey2 = Request.Form("ReqKey2")

or just KISS version

ReqKey1 = Request("ReqKey1")
ReqKey2 = Request("ReqKey2")
0
Bob BenderAuthor Commented:
As a junior developer, I licve and learn.,  When I get back to work Monday, i'll search and try.    

(I hope the last S in KISS is "silly" and nothing else!  ;)
)
0
Bob BenderAuthor Commented:
Trying....  How does the <a> options become part of the Columns in the gird.  I am having trouble as <a> is not a valid name with <Columns>

As for the float, the querystrings are string just that, strings, not float values.  Won't it goof up the value?

A KISS <a> would be great, IF I could get it in the HyperlinkField definition
0
Bob BenderAuthor Commented:
Okay... I changed it to a template field.....
<asp:TemplateField 
    ItemStyle-HorizontalAlign="Center"          
    FooterStyle-HorizontalAlign="Center">
    <ItemTemplate>
        <asp:HyperLink ID="link" runat="server"
             BackColor="#FFF7E7"
             ForeColor="#8C4510"
             NavigateUrl='<%# string.Format("ems_NewAppRequest_Details.aspx?ReqKey1=" + "\"" + Eval("RequestATTUID") + "\""  + "&ReqKey2=" + "\"" + Eval("RequestDate").ToString() + "\"" ) %>'
             Target="_blank"
             Text="Details..." >
        </asp:HyperLink>
    </ItemTemplate>
</asp:TemplateField>

Open in new window

My URL is coming out as
http://ems_NewAppRequest_Details.aspx?ReqKey1="je4383"&ReqKey2="11/18/2014 7:14:02 PM"

All looks fine except the date is wrong and needs to match our DB

Instead  of       "11/18/2014 7:14:02 PM"
I need to see   "2014-10-07 09:31:17.000"

Trying all custom designs I can think of, just aint hit it yet
0
Niladrisekhar DeyCommented:
Use Session
0
Bob BenderAuthor Commented:
a lot of work needed to get it work, but the concept is there from this answer.   Had to change to a TemplateField and Ttrim/SubString  and change the details page to fix it up.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.