Solved

How do I a template field dropdown value into the datanavigateurlformatstring

Posted on 2008-06-20
9
463 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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

A Change in PHP Behavior with Session Write Short Circuit (http://php.net/manual/en/book.session.php#116217) (Winter 2014)** With the release of PHP 5.6 the session handler changed in a way that many think should be considered a bug.  See the note …
Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
This video teaches users how to migrate an existing Wordpress website to a new domain.

828 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