ddl List in data grid web form

queenannsrev

Member
Joined
Jun 28, 2005
Messages
6
Programming Experience
Beginner
(solved) ddl List in data grid web form

I have a data grid and want to add a drop down list. I have seveal ddl on a page have no issue filling them.

The data grid has text boxes no issue there. But I would like to fill a drop down list. I am using the template column and have every thing else working. Check boxes, text boxes but I can't fill the ddl.
I am running a strored procedure to select values from a table to fill the others but I have no clue how to go about filling one in a data grid.

Any help would be appreciated.
 
Last edited:
I fill the data grid with information from the the main table.

I want to fill the ddl with information from another table that I use to populate the ddl. When the data grid is loaded I will then set the
selected.value or .index I forget here but I have code that does this already for other drop downs.

So I guess the steps would be
Fill the ddl then the data grid and set the value of the ddl to that returned from the main table or to blank.

I hope this makes since. I know in my mind what I want to do. I do this on other forms with ddl but not a ddl in a data grid.

Doing so with a ddl is simple. I can't figure it to be much different for a grid.

Code to fill a ddl might go somthing like this.
'*******************************
this is in the page load of one of my pages and use it all the time
strSpName = "Stored procedure name"
ddlDropName = ddlName
NumField = 2
FillDropDown(strSpName, ddlDropName, NumField)

'***********************************************
this is in a module I call Common.
The function is called FillDropDown
Dim ds As DataSet = New DataSet
Try
daSQL.SelectCommand = cmSQL
daSQL.Fill(ds)
strDropName.DataSource = ds
strDropName.DataTextField = ds.Tables(0).Columns(Numfield - 1).ColumnName
strDropName.DataValueField = ds.Tables(0).Columns(0).ColumnName
strDropName.DataBind()
daSQL.Dispose()
cnSQL.Close()
'If you want the user to be able to select a blank value, then uncomment the following two lines
strDropName.Items.Insert(0, "")
strDropName.SelectedIndex = 0
Catch ex As Exception
End Try

I want to use the fill ddl part call my Common function to fill the ddl and then I will set the ddl value.

I hope this clears it up if not let me know.

Thanks
 
I spent some time working on it. I can get the DDL in a datagrid, but databinding it is becoming an issue. The error I keep getting is that "'DataBinding' is not an event of 'System.Web.UI.WebControls.ListItem'"

I'll spend some more time on it this evening and see if there might be a way to assemble a custom web control that inherits everything from a ddl and it's items, but has binding support. No promises though, sorry. :(
 
Back
Top