Solved

Gridview HyperlinkField Help needed

Posted on 2014-12-24
11
138 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 56

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 56

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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 56

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 56

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
 
LVL 56

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

Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

623 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