根据url选择ddl项目



在我的联系人页面(contact.aspx)上,我有一个预订表格,其中包含一个下拉列表控件,该控件动态填充了可供选择的可用司机的姓名。我想做的是在每个驱动程序的单独页面上,例如driver.aspx提供一个"预订此驱动程序"链接,当用户选择该链接时,它们会被带到联系人页面,下拉列表中会填充它们刚刚来自的页面的驱动程序名称。

因此,例如,如果我是查看Pauls驱动程序页面的用户,并且我选择预订该驱动程序,我会被带到联系我们页面,ddl列表已经预先选择paul作为首选驱动程序

这能实现吗?如果是这样的话,并且有人得到了关于如何做到这一点的任何链接或建议?

感谢

Paul

感谢您的回复,我一直忙于这方面的工作,并使用以下方法实现了它(不确定这是最好的方法,但它正在做我需要的)

如果你能提出更好的建议,请告诉我:)

//gets the full url of the referal page e.g http://mysite.co.uk/our-drivers/joe-bloggs.aspx
string refererPage = Request.UrlReferrer.ToString();
//splits the referer url to get the latter part containing the name  e.g joe-bloggs.aspx
string url = refererPage.Split('/').Last();
//splits the url to get the first part of the url e.g joe-bloggs
string url2 = url.Split('.').First();
        // Take the value of url2 replace the hyphen with a space e.g Joe Bloggs then loop through 
        // the items in the DDL and if there is an item that matches make it the selected item
        foreach (ListItem item in ddlPreferedDriver.Items)
        {
            if (url2.ToLower().Replace("-", " ").Contains(item.Text.ToLower()))
            {
                item.Selected = true;
            }
        }

欢呼保罗

最新更新