L
Laura K
Hi.
I am trying to put a drop down in a repeater. I had this working in
dreamweaver but now I am trying to transfer it into VS. I am obviously
missing something. I am getting the following error.
"Object reference not set to an instance of an object"
THe error is referring to the following line which is located in the
function below.
Dim view As New DataView(dsGetProducts.Tables("Products"),
"intProductId = " & intproductId, "intProductId",
DataViewRowState.CurrentRows)
Can anyone shed some light?
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim strProductCode = Request.QueryString("strProductCode")
'create the connection string
Dim connection As New SqlConnection(connectionString)
'Create and initialize the command Object
Dim command As New SqlCommand("New_GetRelationshipProducts",
connection)
command.CommandType = CommandType.StoredProcedure
' Add an input parameter and supply a value for it
command.Parameters.Add("@strProductCode", SqlDbType.NVarChar)
command.Parameters("@strProductCode").Value = strProductCode
' Create SqlDataAdapter and DataSet
Dim mySqlDataAdapter As SqlDataAdapter = New
SqlDataAdapter(command)
Dim dsGetPRoducts As New DataSet
mySqlDataAdapter.Fill(dsGetPRoducts, "products")
'create second table from second stored Proc.
Dim command2 As New SqlCommand("New_GetRelationshipColors",
connection)
command2.CommandType = CommandType.StoredProcedure
Dim mySqlDataAdapter2 As SqlDataAdapter = New
SqlDataAdapter(command2)
mySqlDataAdapter2.Fill(dsGetPRoducts, "colors")
dsGetPRoducts.EnforceConstraints = False
Repeater1.DataSource = dsGetPRoducts.Tables("products")
Repeater1.DataBind()
dsGetPRoducts.Relations.Add("ColorRelation",
referenceDataSet.Tables("Products").Columns("intProductId"),
referenceDataSet.Tables("Sizes").Columns("intProductId"))
End Sub
Function GetChildRows(ByVal dataItem As Object, ByVal relation As
String) As DataView
Dim drv As DataRowView = CType(dataItem, DataRowView)
If (Not drv Is Nothing) Then
' extracting the ProductId from the current row item
Dim intproductId As Int32 =
Convert.ToInt32(drv("intProductId"))
' filtering reference dataset to get the specific Product
row
' which also gets all the Color rows for this Product
Dim view As New DataView(dsGetProducts.Tables("Products"),
"intProductId = " & intproductId, "intProductId",
DataViewRowState.CurrentRows)
' the one and only Product for that ProductId
criteria/filter
Dim productRow As DataRowView = view(0)
' this is where the 'child rows' of colors are retrieved
for the Product
' in question
Return productRow.CreateChildView(relation)
End If
Return Nothing
End Function
The HTML is
<asp:repeater id="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td>
<%# DataBinder.Eval(Container, "DataItem.IntProductID") %>
</td>
<td>
<%# Container.DataItem("strProductName") %>
</td>
<td>
<asp:dropdownlist DataSource='<%# GetChildRows( Container.DataItem,
"ColorRelation" ) %>' Runat="server" DataTextField="strColorID">
</asp:dropdownlist>
</td>
</tr>
</ItemTemplate>
</asp:repeater>
I am trying to put a drop down in a repeater. I had this working in
dreamweaver but now I am trying to transfer it into VS. I am obviously
missing something. I am getting the following error.
"Object reference not set to an instance of an object"
THe error is referring to the following line which is located in the
function below.
Dim view As New DataView(dsGetProducts.Tables("Products"),
"intProductId = " & intproductId, "intProductId",
DataViewRowState.CurrentRows)
Can anyone shed some light?
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim strProductCode = Request.QueryString("strProductCode")
'create the connection string
Dim connection As New SqlConnection(connectionString)
'Create and initialize the command Object
Dim command As New SqlCommand("New_GetRelationshipProducts",
connection)
command.CommandType = CommandType.StoredProcedure
' Add an input parameter and supply a value for it
command.Parameters.Add("@strProductCode", SqlDbType.NVarChar)
command.Parameters("@strProductCode").Value = strProductCode
' Create SqlDataAdapter and DataSet
Dim mySqlDataAdapter As SqlDataAdapter = New
SqlDataAdapter(command)
Dim dsGetPRoducts As New DataSet
mySqlDataAdapter.Fill(dsGetPRoducts, "products")
'create second table from second stored Proc.
Dim command2 As New SqlCommand("New_GetRelationshipColors",
connection)
command2.CommandType = CommandType.StoredProcedure
Dim mySqlDataAdapter2 As SqlDataAdapter = New
SqlDataAdapter(command2)
mySqlDataAdapter2.Fill(dsGetPRoducts, "colors")
dsGetPRoducts.EnforceConstraints = False
Repeater1.DataSource = dsGetPRoducts.Tables("products")
Repeater1.DataBind()
dsGetPRoducts.Relations.Add("ColorRelation",
referenceDataSet.Tables("Products").Columns("intProductId"),
referenceDataSet.Tables("Sizes").Columns("intProductId"))
End Sub
Function GetChildRows(ByVal dataItem As Object, ByVal relation As
String) As DataView
Dim drv As DataRowView = CType(dataItem, DataRowView)
If (Not drv Is Nothing) Then
' extracting the ProductId from the current row item
Dim intproductId As Int32 =
Convert.ToInt32(drv("intProductId"))
' filtering reference dataset to get the specific Product
row
' which also gets all the Color rows for this Product
Dim view As New DataView(dsGetProducts.Tables("Products"),
"intProductId = " & intproductId, "intProductId",
DataViewRowState.CurrentRows)
' the one and only Product for that ProductId
criteria/filter
Dim productRow As DataRowView = view(0)
' this is where the 'child rows' of colors are retrieved
for the Product
' in question
Return productRow.CreateChildView(relation)
End If
Return Nothing
End Function
The HTML is
<asp:repeater id="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td>
<%# DataBinder.Eval(Container, "DataItem.IntProductID") %>
</td>
<td>
<%# Container.DataItem("strProductName") %>
</td>
<td>
<asp:dropdownlist DataSource='<%# GetChildRows( Container.DataItem,
"ColorRelation" ) %>' Runat="server" DataTextField="strColorID">
</asp:dropdownlist>
</td>
</tr>
</ItemTemplate>
</asp:repeater>