Solved

How do I a template field dropdown value into the datanavigateurlformatstring

Posted on 2008-06-20
9
472 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

 Watch the Recording: Learning MySQL 5.7

MySQL 5.7 has a lot of new features. If you've dabbled with an older version of MySQL, it is definitely worth learning.

Question has a verified solution.

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

Using Quotation Marks in PHP This question (http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28217211.html) seems to come up a lot for developers who are new to PHP.  And it got me thinking, "How can we explain the rule…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
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…

623 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