Solved

How do I a template field dropdown value into the datanavigateurlformatstring

Posted on 2008-06-20
9
454 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
 
LVL 14

Expert Comment

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

Thanks,
Dustin
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
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.

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now