?
Solved

Gridview with Hyperlink column questions

Posted on 2014-12-17
3
Medium Priority
?
276 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 1000 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 1000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

770 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