ASP.NET dynamic data sets default value for drop-down list

I have a drop-down list (FK) that I would like to set and display a default value based on the login ID. Could you tell me how to do this? I just want to influence the drop-down filter that appears at the top above the Gridview.

thanks

Nikos

+3
source share
4 answers

If you need this feature only in the DropDown list that appears in the Filter Criteria section, simply change the URL by adding the QueryString parameters that you want to filter. DynamicFilter will select values ​​from QueryString and configure DropDown lists accordingly. (fyi. This is the same functionality as ExternalKey.ascx FieldTemplate)

It would be nice if there was a better way to create this URL (instead of using a string), but as of right now any solution that I provide is likely to break in the next version.

example (in page_load)

Response.Redirect("~/Employees/List.aspx?ReportsTo=1234");
0
source

Is this a universal change, or is it just for dealing with a foreign key?

, FieldTemplate, . FieldTemplate FieldTemplate "ForeignKey". New FieldTemplate OnDataBinding ( Page_PreRender), " " DropDownList.

, New FieldTemplate , System.ComponentModel.DataAnnotations. UIHint Entity, . ( )

http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.uihintattribute.uihint.aspx http://www.asp.net/learn/3.5-SP1/video-291.aspx ( 07:30 .)

DynamicData Futures CodePlex. , " ". http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=14475

0

, .

FilterUserControl.ascx.cs, Page_Init PopulateListControl (DropDownList1);

DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByText( "" ));//

, Partial Entity , , .

0

, , : ItemCreated :

       foreach (DetailsViewRow row in DetailsView1.Rows)
        {
            foreach (Control ctl in row.Controls)
                foreach (Control c in ctl.Controls)
                    foreach (Control x in c.Controls)
                    {
                        if (x.ClientID.Contains("tblName"))
                        {
                            foreach (Control y in x.Controls)
                            {
                                if (y.ClientID.Contains("DropDownList"))
                                {
                                    ddl = y as DropDownList;
                                    ddl.SelectedValue = Convert.ToString(UserId);
                                    ddl.Enabled = false;
                                }
                            }
                        }
                    }
        }

, - (tblName), (fk to userId) .

0

Source: https://habr.com/ru/post/1711468/


All Articles