Solved

How do I a template field dropdown value into the datanavigateurlformatstring

Posted on 2008-06-20
9
470 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
[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
  • 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
DevOps Toolchain Recommendations

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

 
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 250 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
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.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

732 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