Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I a template field dropdown value into the datanavigateurlformatstring

Posted on 2008-06-20
9
Medium Priority
?
478 Views
Last Modified: 2013-11-26
How would I get the value of a templatefield dropdown into the datanavigateurlstring property within a gridview edit columns using vs2005

I am using the following

Datanavigateurlfields = job_no,Column[6]

Datanavigateurlformatstring = savetime.aspx?job_no={0}&start travel={1}

job_no gets the value but I can get the start_travel value from the dropdown list in column6

This is using the gridview tasks option in vs and not programatically

0
Comment
Question by:csintera
  • 5
  • 3
9 Comments
 
LVL 14

Expert Comment

by:Dustin Hopkins
ID: 21839760
the Datanavigateurlfields  property accepts the datafield/dataitem values, not a specific column value.
0
 

Author Comment

by:csintera
ID: 21839788
But it accepts the job_no bounditem column as a column value,  but not the templatefields coulum
0
 
LVL 14

Expert Comment

by:Dustin Hopkins
ID: 21839793
what dataitem is the ddl in column[6] bound to?
0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
LVL 14

Expert Comment

by:Dustin Hopkins
ID: 21839795
If you could post the code for your gridview, that would help...

Thanks,
Dustin
0
 

Author Comment

by:csintera
ID: 21839801
 <asp:TemplateField HeaderText="Finish Travel">
                            <ControlStyle BackColor="ControlLightLight" BorderColor="Gray" Width="75px" />
                            <ItemStyle Width="75px" />
                            <ItemTemplate>
                                &nbsp;<asp:DropDownList ID="DropDownList1" runat="server">
                                    <asp:ListItem>01:00</asp:ListItem>
                                    <asp:ListItem>01:15</asp:ListItem>
                                    <asp:ListItem>01:30</asp:ListItem>
                                    <asp:ListItem>01:45</asp:ListItem>
                                    <asp:ListItem>02:00</asp:ListItem>
                                    <asp:ListItem>02:15</asp:ListItem>
                                    <asp:ListItem></asp:ListItem>
                                    <asp:ListItem></asp:ListItem>
                                    <asp:ListItem></asp:ListItem>
                                </asp:DropDownList>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:HyperLinkField DataNavigateUrlFields="job_no,dropdownlist1" DataNavigateUrlFormatString="savetime.aspx?job_no={0}&amp;finish travel={1}"
                            HeaderText="Save " Target="_top" Text="Save" />
                    </Columns>

so I want to get the value of finish travel dropdownlist1 into the urlstring
0
 
LVL 14

Accepted Solution

by:
Dustin Hopkins earned 750 total points
ID: 21839857
OK here is the problem, the hyperlink field is populated when the gridview rows are bound, and the datanavigateurlfields property can only be set to actual dataitems, you could do what you want to do the way you want to do it if your dropdownlist was bound to a dataitem. However you can accomplish this by using the code behind.
I will provide a generic example below.
First you need to convert your hyperlinkfield to a template field and add an onselectedindexchanged event handler to the dropdownlist.
NOTE: If you're storing the time in the database, why not just handle the update on this page using the gridview, it would be much simpler than what is set up here.

<asp:TemplateField>
                    <ItemTemplate>
                        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
                            onselectedindexchanged="DropDownList1_SelectedIndexChanged">
                            <asp:ListItem>1</asp:ListItem>
                            <asp:ListItem>2</asp:ListItem>
                            <asp:ListItem>3</asp:ListItem>
                        </asp:DropDownList>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:HyperLink ID="HyperLink1" runat="server"  NavigateUrl='<%# Eval("job_no", savetime.aspx?job_no={0}") %>'
                            Text="Save"></asp:HyperLink>
                    </ItemTemplate>
                </asp:TemplateField>
'Code behind objects
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim s As DropDownList = sender
        For Each row As GridViewRow In GridView1.Rows
            Dim ddl As DropDownList = row.FindControl("DropDownList1")
            If ddl.UniqueID = s.UniqueID Then
                Dim hl As HyperLink = row.FindControl("HyperLink1")
                hl.NavigateUrl = "savetime.aspx?job=" & row.Cells(1).Text & "&finishtravel=" & ddl.SelectedValue 'NOTE: row.cells(1).text should be set to the cell that contains the job_no
            End If
        Next
 
    End Sub
    Sub gridviewrowdb(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim ddl As DropDownList = e.Row.FindControl("DropDownList1")
            Dim hl As HyperLink = e.Row.FindControl("HyperLink1")
            hl.NavigateUrl = "savetime.aspx?job=" & DataBinder.Eval(e.Row.DataItem, "job_no") & "&finishtravel=" & ddl.SelectedValue
        End If
    End Sub

Open in new window

0
 

Author Comment

by:csintera
ID: 21875484
Yes this optioned worked
0
 
LVL 14

Expert Comment

by:Dustin Hopkins
ID: 21875692
Were you going to accept that as the solution since it worked?
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Developer tools in browsers have been around for a while, yet they are still heavily underused by developers. Developers still fix html or CSS then refresh page to see effect, or they put alert or debugger in JavaScript and then try again and again …
A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

963 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