Junco
Junco

Reputation: 281

How do I get values from Templates in a datagrid row for a query string?

I have two Template fields in a datagrid whose values I need to pass in a query string in a Hyperlink field in the datagrid. The first value I need is the Nest Number. The second is the Park Name. How do I put those values in the querystring?

Here is the start of the gridview with the two Templates:

<asp:GridView ID="NestListGrid" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" Width="95%" OnRowCancelingEdit="NestListGrid_RowCancelingEdit" OnRowEditing="NestListGrid_RowEditing" OnRowUpdating="NestListGrid_RowUpdating" >
        <Columns>
            <asp:BoundField DataField="NestID" Visible="False" />
            <asp:TemplateField HeaderText="Nest Nbr">
                <EditItemTemplate>
                    <asp:TextBox ID="NestNumber_tbx" Width="100px" MaxLength="10" runat="server" Text='<%# Bind("NestNumber") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="NestNumber_lbl" runat="server" Text='<%# Bind("NestNumber") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>

            <asp:TemplateField HeaderText="Park">
                <EditItemTemplate>
                    <asp:DropDownList ID="Park_ddl" runat="server" DataSourceID="ParkIDNameGridViewDDL_SDS"
                        DataTextField="ParkName" DataValueField="ParkID" SelectedValue='<%# Bind("ParkID") %>' >
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="ParkName_lbl" runat="server" Text='<%# Bind("ParkName") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>

...etc...

Here is the Hyperlink Query String later in the datagrid:

<asp:HyperLinkField Text="Nest Info" DataNavigateUrlFields="NestID" DataNavigateUrlFormatString="NestInfoUser.aspx?NestID={0}&NestNumber={0}&ParkName={0}" />

-

Upvotes: 0

Views: 300

Answers (1)

Win
Win

Reputation: 62260

You can use with comma.

<asp:HyperLinkField Text="Nest Info" DataNavigateUrlFields="NestID,ParkName"
    DataNavigateUrlFormatString="NestInfoUser.aspx?NestNumber={0}&ParkName={1}" />

Upvotes: 0

Related Questions