Gridview dropdownlist in c# code [modified]
-
Greetings, I'm working on a web application with a dynamically creation of a gridview and within this gridview a dropdownlist (ddl) for data validation; Everything needs to be programmed dynamically in c# code. The creation of the grid + data is very easy, but on 1 field I want a ddl, so that people can only choose from certain data in this ddl. //GridView GridView2 = new GridView(); GridView2.ID = "Ellende"; GridView2.AutoGenerateColumns = false; //GridView1.DataKeyNames = new string[] { "EmployeeID" }; GridView2.AllowPaging = true; GridView2.AllowSorting = true; GridView2.PageSize = 5; BoundField bfName = new BoundField(); BoundField bf1 = new BoundField(); BoundField bf2 = new BoundField(); CommandField cf = new CommandField(); cf.ButtonType = ButtonType.Button; cf.ShowCancelButton = true; cf.ShowSelectButton = true; bf1.DataField = "Task1"; bf1.HeaderText = "Task1"; TemplateField tf1 = new TemplateField(); tf1.HeaderText = "Task1"; DropDownList dl1 = new DropDownList(); dl1.DataSource = ObjectDataSource3; dl1.DataValueField = "Recid"; dl1.DataTextField = "Status"; dl1.SelectedValue = "Task1"; GridView2.Controls.Add(dl1); GridView2.Columns.Add(tf1); //GridView2.Columns.Add(bf1); bfName.HeaderText = "Employee Name"; bfName.DataField = "Name"; bfName.ReadOnly = true; bf2.HeaderText = "Task2"; bf2.DataField = "Task2"; bf2.ReadOnly = true; GridView2.Columns.Add(cf); GridView2.Columns.Add(bfName); //GridView2.Columns.Add(bf1); GridView2.Columns.Add(bf2); GridView2.Columns.Add(bf3); GridView2.DataSource = DT; GridView2.Visible = true; GridView2.DataBind(); The main problem is that under "Task1" I need to connect the dropdownlist somehow to the gridview when using c# code dynamically. I found out that I need a templatefield. The gridview is filled with data when using a dataset--> that easy. But the field with "Task1" needs to be connected with a ddl, from which a choice can be made. When choosing a value from the ddl --> this value needs to be stored in the datatable DT. How can I connect a DDL (with predefined data) in a gridview???? I hope somebody has an answer in c# or VB Greetings Peter Bellen -- modified at 16:17
-
Greetings, I'm working on a web application with a dynamically creation of a gridview and within this gridview a dropdownlist (ddl) for data validation; Everything needs to be programmed dynamically in c# code. The creation of the grid + data is very easy, but on 1 field I want a ddl, so that people can only choose from certain data in this ddl. //GridView GridView2 = new GridView(); GridView2.ID = "Ellende"; GridView2.AutoGenerateColumns = false; //GridView1.DataKeyNames = new string[] { "EmployeeID" }; GridView2.AllowPaging = true; GridView2.AllowSorting = true; GridView2.PageSize = 5; BoundField bfName = new BoundField(); BoundField bf1 = new BoundField(); BoundField bf2 = new BoundField(); CommandField cf = new CommandField(); cf.ButtonType = ButtonType.Button; cf.ShowCancelButton = true; cf.ShowSelectButton = true; bf1.DataField = "Task1"; bf1.HeaderText = "Task1"; TemplateField tf1 = new TemplateField(); tf1.HeaderText = "Task1"; DropDownList dl1 = new DropDownList(); dl1.DataSource = ObjectDataSource3; dl1.DataValueField = "Recid"; dl1.DataTextField = "Status"; dl1.SelectedValue = "Task1"; GridView2.Controls.Add(dl1); GridView2.Columns.Add(tf1); //GridView2.Columns.Add(bf1); bfName.HeaderText = "Employee Name"; bfName.DataField = "Name"; bfName.ReadOnly = true; bf2.HeaderText = "Task2"; bf2.DataField = "Task2"; bf2.ReadOnly = true; GridView2.Columns.Add(cf); GridView2.Columns.Add(bfName); //GridView2.Columns.Add(bf1); GridView2.Columns.Add(bf2); GridView2.Columns.Add(bf3); GridView2.DataSource = DT; GridView2.Visible = true; GridView2.DataBind(); The main problem is that under "Task1" I need to connect the dropdownlist somehow to the gridview when using c# code dynamically. I found out that I need a templatefield. The gridview is filled with data when using a dataset--> that easy. But the field with "Task1" needs to be connected with a ddl, from which a choice can be made. When choosing a value from the ddl --> this value needs to be stored in the datatable DT. How can I connect a DDL (with predefined data) in a gridview???? I hope somebody has an answer in c# or VB Greetings Peter Bellen -- modified at 16:17
You may like to post this in C# forum instead. C# Forum is here: http://www.codeproject.com/script/comments/forums.asp?forumid=1649[^]
Vasudevan Deepak Kumar Personal Homepage Tech Gossips
-
Greetings, I'm working on a web application with a dynamically creation of a gridview and within this gridview a dropdownlist (ddl) for data validation; Everything needs to be programmed dynamically in c# code. The creation of the grid + data is very easy, but on 1 field I want a ddl, so that people can only choose from certain data in this ddl. //GridView GridView2 = new GridView(); GridView2.ID = "Ellende"; GridView2.AutoGenerateColumns = false; //GridView1.DataKeyNames = new string[] { "EmployeeID" }; GridView2.AllowPaging = true; GridView2.AllowSorting = true; GridView2.PageSize = 5; BoundField bfName = new BoundField(); BoundField bf1 = new BoundField(); BoundField bf2 = new BoundField(); CommandField cf = new CommandField(); cf.ButtonType = ButtonType.Button; cf.ShowCancelButton = true; cf.ShowSelectButton = true; bf1.DataField = "Task1"; bf1.HeaderText = "Task1"; TemplateField tf1 = new TemplateField(); tf1.HeaderText = "Task1"; DropDownList dl1 = new DropDownList(); dl1.DataSource = ObjectDataSource3; dl1.DataValueField = "Recid"; dl1.DataTextField = "Status"; dl1.SelectedValue = "Task1"; GridView2.Controls.Add(dl1); GridView2.Columns.Add(tf1); //GridView2.Columns.Add(bf1); bfName.HeaderText = "Employee Name"; bfName.DataField = "Name"; bfName.ReadOnly = true; bf2.HeaderText = "Task2"; bf2.DataField = "Task2"; bf2.ReadOnly = true; GridView2.Columns.Add(cf); GridView2.Columns.Add(bfName); //GridView2.Columns.Add(bf1); GridView2.Columns.Add(bf2); GridView2.Columns.Add(bf3); GridView2.DataSource = DT; GridView2.Visible = true; GridView2.DataBind(); The main problem is that under "Task1" I need to connect the dropdownlist somehow to the gridview when using c# code dynamically. I found out that I need a templatefield. The gridview is filled with data when using a dataset--> that easy. But the field with "Task1" needs to be connected with a ddl, from which a choice can be made. When choosing a value from the ddl --> this value needs to be stored in the datatable DT. How can I connect a DDL (with predefined data) in a gridview???? I hope somebody has an answer in c# or VB Greetings Peter Bellen -- modified at 16:17
gridview is not that much good in doing such a custom stuff u r doing, u can do it with some programming technique but i think that would be so complicated to get desired result and functionality which is required, u shoud better use any third party controll for that purpose .
hello