Link to home
Start Free TrialLog in
Avatar of Isaac
IsaacFlag for United States of America

asked on

Gridview and querystring

I have a gridview that has 5 columns.  The 5th column is an edit link.
How can I use one or more of the bound fields in the querystring?

The way I did it is not working:
<asp:HyperLinkField NavigateUrl="editAttorney.aspx?mi=<% Eval("Assigned") %>" Text="Edit" />

Thanks!
<asp:GridView ID="GridView2" runat="server" AllowPaging="True" 
        AllowSorting="True" AutoGenerateColumns="False" 
        DataSourceID="orclDataSource" CellPadding="3" CellSpacing="1" Font-Size="Small" 
        ForeColor="#333333" GridLines="None" HorizontalAlign="Center" PageSize="20" 
        Width="85%">
        <RowStyle BackColor="#EFF3FB" />
        <Columns>
            <asp:BoundField DataField="ASSIGNED" HeaderText="Initials" 
                SortExpression="ASSIGNED" />
            <asp:BoundField DataField="ASSIGNED_LAST_NAME" HeaderText="Last Name" 
                SortExpression="ASSIGNED_LAST_NAME" />
            <asp:BoundField DataField="ASSIGNED_FIRST_NAME" HeaderText="First Name" 
                SortExpression="ASSIGNED_FIRST_NAME" />
            <asp:BoundField DataField="ASSIGNED_MI" HeaderText="Middle Initials" 
                SortExpression="ASSIGNED_MI" />
            <asp:HyperLinkField NavigateUrl="editAttorney.aspx" Text="Edit" />
        </Columns>
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#2461BF" />
        <AlternatingRowStyle BackColor="White" />
    </asp:GridView>

Open in new window

Avatar of Ramone_Hamilton
Ramone_Hamilton
Flag of United States of America image

Doesn't Eval return object?  Does <% Eval("Assigned") as string %> work?  What error are you getting?
Avatar of Isaac

ASKER

Error Creating Control - GridView2
Literal content ('asp:HyperLinkField NavigateUrl=editAttorney.aspx?mi=") is not allowed within a 'System.Web.UI.WebControls.DataControlFieldConllection'.
Try NavigateUrl = 'editAttorney.aspx?mi= <% Eval("ASSIGNED") as string %>'
Avatar of Isaac

ASKER

That's what I tried and to get the error
How about: NavigateUrl = 'editAttorney.aspx?mi= <%# Eval("ASSIGNED") as string %>'
Sorry I forgot the # sound last time.
I am telling you wrong, you are using a hyperLink, my previous methods would work with a bindable control like a label.  You want to use the DataFormatUrl

<asp:HyperLinkField NavigateUrl="editAttorney.aspx" Text="Edit" DataNavigateUrlFormatString="editAttorney.aspx?mi={0}" DataTextField="ASSIGNED"
 />

Open in new window

Avatar of Isaac

ASKER

That's not working the way it should.
Now I get the value of "ASSIGNED" as a link in my edit column.
Basically the data in the table for "ASSIGNED" is rendered in the edit column.
ASKER CERTIFIED SOLUTION
Avatar of Rajar Ahmed
Rajar Ahmed
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Wow I forgot the DataNavigateUrlFields.  Can't get any better than that.