pothuri Posted March 22, 2006 Posted March 22, 2006 hi all, I have a web page with three list boxes and based on the selection of these i populate the datagrid with a dropdown box in each of the cell. Since I am not sure of the num of cols that the datagrid is going to have untill the selection of 3 listboxes i cannot use template columns. I query the database with the selection, get a table and bind the datagrid with this table. On datagrid's itemdatabound() i add these dropdown boxes in each of the cell of the datagrid. The user could select from the dropdown box and click the submit button. As you all might know when the submit is clicked all the dynamically created controls vanish. Hence I am not able get the user selected values so that i could update the database. i am using C#. I would really appreciate if anyone could help me in this regard. thanks. Quote
MisterB Posted March 27, 2006 Posted March 27, 2006 Hi try to do this. Partial Class _Default Inherits System.Web.UI.Page Protected Sub DataGrid1_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemCreated '-- This is just for testing.. Dim DDbox As New DropDownList Dim IntCounter As Integer Dim DgCell As New TableCell '-- Fill the dropDownBox with dummy data For IntCounter = 0 To 5 DDbox.Items.Add("Item " + IntCounter.ToString) Next '-- Put the filled DDbox in a cell DgCell.Controls.Add(DDbox) '-- add the cell to the Datagrid e.Item.Cells.Add(DgCell) End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim DgRow As DataGridItem Dim DDBox As New DropDownList ListBox3.Items.Clear() '-- loop thru the rows of the datagrid For Each DgRow In DataGrid1.Items '-- set te DDbox control DDBox = DgRow.Cells(3).Controls(0) '-- add the selected item value to the result listbox or your own result object :) ListBox3.Items.Add(DDBox.SelectedItem.ToString) Next End Sub End Class Good luck! MrB Quote
pothuri Posted March 28, 2006 Author Posted March 28, 2006 Thanks MisterB for the reply. I will try that. pavan. Hi try to do this. Partial Class _Default Inherits System.Web.UI.Page Protected Sub DataGrid1_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemCreated '-- This is just for testing.. Dim DDbox As New DropDownList Dim IntCounter As Integer Dim DgCell As New TableCell '-- Fill the dropDownBox with dummy data For IntCounter = 0 To 5 DDbox.Items.Add("Item " + IntCounter.ToString) Next '-- Put the filled DDbox in a cell DgCell.Controls.Add(DDbox) '-- add the cell to the Datagrid e.Item.Cells.Add(DgCell) End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim DgRow As DataGridItem Dim DDBox As New DropDownList ListBox3.Items.Clear() '-- loop thru the rows of the datagrid For Each DgRow In DataGrid1.Items '-- set te DDbox control DDBox = DgRow.Cells(3).Controls(0) '-- add the selected item value to the result listbox or your own result object :) ListBox3.Items.Add(DDBox.SelectedItem.ToString) Next End Sub End Class Good luck! MrB Quote
pothuri Posted April 3, 2006 Author Posted April 3, 2006 Hi MisterB, I have tried you suggestion. But the controls still vanish. pavan. Hi try to do this. Partial Class _Default Inherits System.Web.UI.Page Protected Sub DataGrid1_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemCreated '-- This is just for testing.. Dim DDbox As New DropDownList Dim IntCounter As Integer Dim DgCell As New TableCell '-- Fill the dropDownBox with dummy data For IntCounter = 0 To 5 DDbox.Items.Add("Item " + IntCounter.ToString) Next '-- Put the filled DDbox in a cell DgCell.Controls.Add(DDbox) '-- add the cell to the Datagrid e.Item.Cells.Add(DgCell) End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim DgRow As DataGridItem Dim DDBox As New DropDownList ListBox3.Items.Clear() '-- loop thru the rows of the datagrid For Each DgRow In DataGrid1.Items '-- set te DDbox control DDBox = DgRow.Cells(3).Controls(0) '-- add the selected item value to the result listbox or your own result object :) ListBox3.Items.Add(DDBox.SelectedItem.ToString) Next End Sub End Class Good luck! MrB Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.