Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Trying to build ddl during Datagrid Edit Command

Author  Topic 

bubberz
Constraint Violating Yak Guru

289 Posts

Posted - 2005-09-05 : 23:06:14
When I run this code I get:
Object reference not set to an instance of an object.

It's referring to the line of:
ddlTitle1.DataSource = DS

Here's the code:

Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand
DataGrid1.EditItemIndex = e.Item.ItemIndex
'Build the DDL For the Title section
Con1.Open()
Dim strDDL As String
strDDL = "SELECT DISTINCT Title FROM Employees ORDER BY Title"
Dim da As New OleDb.OleDbDataAdapter()
da.SelectCommand = New OleDb.OleDbCommand(strDDL, Con1)
Dim DS As New DataSet()
da.Fill(DS)
Dim ddlTitle1 As DropDownList = e.Item.FindControl("ddlTitle")

ddlTitle1.DataSource = DS
ddlTitle1.DataMember = "Employees"
ddlTitle1.DataTextField = "Title"
ddlTitle1.DataValueField = "Title"
ddlTitle1.DataBind()
Con1.Close()

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2005-09-06 : 14:49:12
Check out Part 7 of Scott Mitchell's Series on Examining the Data Grid.

---------------------------
EmeraldCityDomains.com
Go to Top of Page

olay80
Yak Posting Veteran

62 Posts

Posted - 2005-09-07 : 09:57:42
maybe ur not the dropdown object is not being instentiated correctly that's why it's not getting the datasource DS

Oliver
Go to Top of Page
   

- Advertisement -