Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted

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

Posted

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

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...