Solved

Gridview HyperlinkField Help needed

Posted on 2014-12-24
11
123 Views
Last Modified: 2014-12-31
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?
0
Comment
Question by:Bob Bender
  • 5
  • 5
11 Comments
 
LVL 51

Expert Comment

by:HainKurt
ID: 40516754
use escape

please post some code... how you put it into link, and how you retrieve and use it...
0
 
LVL 5

Author Comment

by:Bob Bender
ID: 40517118
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
 
LVL 51

Accepted Solution

by:
HainKurt earned 500 total points
ID: 40517152
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
 
LVL 51

Expert Comment

by:HainKurt
ID: 40517178
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
 
LVL 51

Expert Comment

by:HainKurt
ID: 40517180
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 51

Expert Comment

by:HainKurt
ID: 40517182
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
 
LVL 5

Author Comment

by:Bob Bender
ID: 40519713
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
 
LVL 5

Author Comment

by:Bob Bender
ID: 40521881
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
 
LVL 5

Author Comment

by:Bob Bender
ID: 40522105
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
 
LVL 1

Expert Comment

by:Niladrisekhar Dey
ID: 40525589
Use Session
0
 
LVL 5

Author Closing Comment

by:Bob Bender
ID: 40526231
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

930 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

15 Experts available now in Live!

Get 1:1 Help Now