Solved

Gridview with Hyperlink column questions

Posted on 2014-12-17
3
274 Views
Last Modified: 2014-12-19
I have a GridView with 3 columns.   One of those columns is a HyperlinkField, using another column as a QueryString entry.

Code looks like this...

      <Columns>
          <asp:BoundField DataField="ContactUs_intended_for" HeaderText="Team" ReadOnly="True">
                 <HeaderStyle HorizontalAlign="Center" />
                 <ItemStyle HorizontalAlign="Center" />
          </asp:BoundField>

          <asp:BoundField DataField="ContactUs_subject" HeaderText="Subject" ReadOnly="True" >
                  <ItemStyle HorizontalAlign="Left" />
          </asp:BoundField>

          <asp:HyperLinkField 
                    DataNavigateUrlFields="ContactUs_intended_for"
                    DataNavigateUrlFormatString="Contact_Us_Details.aspx?Team={0}"
                    Text="Details..."  >
          </asp:HyperLinkField>
      </Columns>

Open in new window


Works good now, as the QueryString field is filled from the column for that has the "ContactUs_intended_for" value.
Therefore, I am tjhinking that only entries that can used in the DataNavigateUrlFormatString property have to be from the GridView...  Is that true?

I need to change the source of the data for the QueryString entries to new DropDown boxes added for the following.
Team named "filterTeam"  and  Status named "filterStatus"

Can I fill the "DataNavigateUrlFields" with the  filterTeam.SelectedValue.Text, filterStatus.SelectedValue.Text  entries?
If not, is there an event that is used that I can create the DataNavigateUrlFormatString with the URL info I need?

I hope that made sense...

Bob
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
3 Comments
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 250 total points
ID: 40506654
You're correct about only being able to implicitly bind to properties of the data source. In order to do what you want, you will need to override the RowDataBound event of the grid and manually alter the URL for the hyperlink.

Something like:
<!-- Grid with two drop downs for filters -->
<label for="filterTeam">Team</label>
<asp:DropDownList ID="filterTeam" runat="server">
    <asp:ListItem Value="1" Text="Team 1" />
    <asp:ListItem Value="2" Text="Team 2" />
</asp:DropDownList>

<label for="filterStatus">Status</label>
<asp:DropDownList ID="filterStatus" runat="server">
    <asp:ListItem Value="1" Text="Open" />
    <asp:ListItem Value="2" Text="Approved" />
    <asp:ListItem Value="3" Text="Closed" />
</asp:DropDownList>

<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound">
    <Columns>
        <asp:BoundField DataField="ContactUs" HeaderText="Team" ReadOnly="true">
            <HeaderStyle HorizontalAlign="Center" />
            <ItemStyle HorizontalAlign="Center" />
        </asp:BoundField>
        <asp:BoundField DataField="ContactUsSubject" HeaderText="Subject" ReadOnly="true">
            <ItemStyle HorizontalAlign="Left" />
        </asp:BoundField>
        <asp:HyperLinkField Text="Details" />
    </Columns>
</asp:GridView>

Open in new window

And the event itself:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        // grab the values from the filter drop downs
        string team = filterTeam.SelectedValue;
        string status = filterStatus.SelectedValue;

        // rebuild the URL for the hyperlink column
        HyperLink link = e.Row.Cells[2].Controls[0] as HyperLink;
        link.NavigateUrl = string.Format("Details.aspx?team={0}&status={1}", team, status);
    }
}

Open in new window

0
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 250 total points
ID: 40506660
no. can come from any field on the row.

I build 2 different hyperlinks in a row. one using a hyperlink template field, the other using a label and create the html manually,

from my working app.
                <ItemTemplate>
                    <asp:HyperLink ID="HyperLinkDocId" runat="server" Text="_manual_load"></asp:HyperLink>
                    <asp:HiddenField ID="HF_DocNo" runat="server" Value='<%# Bind("DocNo") %>' />
                    <asp:HiddenField ID="HF_RevNo" runat="server" Value='<%# Bind("RevisionNo") %>' />
                </ItemTemplate>
            <asp:TemplateField HeaderText="File List" SortExpression="FileList">
                <ItemTemplate>
                    <asp:Label ID="LabelFileLinks" runat="server" Text="_manual_load"></asp:Label>
                </ItemTemplate>

                <ItemStyle HorizontalAlign="Center" Width="50px" />

            </asp:TemplateField>

Open in new window


in code behind...
    protected void GridViewProjDocs_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {

            // determine the value of the Hyperlink field
            HyperLink hlDocId = ((HyperLink)e.Row.FindControl("HyperLinkDocId"));
            Label filelinks = (Label)e.Row.FindControl("LabelFileLinks");
            Label Title = (Label)e.Row.FindControl("lblTitle");
            
            CheckBoxList chkFiles = (CheckBoxList)e.Row.FindControl("cklstFiles");

            DataRowView row = (DataRowView)e.Row.DataItem;

            //build the link to Document details page
            hlDocId.NavigateUrl = String.Format("details_prjdoc.aspx?DocNo={0}", row["DocNo"]);
            hlDocId.Text = row["DocId"].ToString();

                        filelinks.Text += "<a href='" + Server.UrlPathEncode(thisURL) + string.Format("' target = '_blank'>" + "<img src='../images/icon-{0}.png' height='20' width='20' border='0' alt='{0}' /></a>", images[i]);
                        filelinks.Text += "&nbsp;";

Open in new window

0
 
LVL 5

Author Comment

by:Bob Bender
ID: 40509934
Thanx folks!   I understand most of that and moving forward.   NOW, to only get 2 QueryStrings (needed for a composite key on a SQL database in the detailsView page.  

I think I can use the RowBound event to build the URL and combine the fields into a single string and pass thru it.

Bob
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

729 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