Solved

Gridview HyperlinkField Help needed

Posted on 2014-12-24
11
130 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
[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
  • 5
  • 5
11 Comments
 
LVL 53

Expert Comment

by:Huseyin KAHRAMAN
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 53

Accepted Solution

by:
Huseyin KAHRAMAN 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
Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

 
LVL 53

Expert Comment

by:Huseyin KAHRAMAN
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 53

Expert Comment

by:Huseyin KAHRAMAN
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
 
LVL 53

Expert Comment

by:Huseyin KAHRAMAN
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

Technology Partners: 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

Suggested Solutions

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…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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