Solved

Gridview HyperlinkField Help needed

Posted on 2014-12-24
11
121 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

759 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

21 Experts available now in Live!

Get 1:1 Help Now