Logo 
Search:

Asp.net Answers

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds
  Question Asked By: Zobah Mizrachi   on Dec 18 In Asp.net Category.

  
Question Answered By: Calais Bernard   on Dec 18

This is kicking by Butt! I can't figure out what
the problem is. I keep getting the "Object reference
not set to an instance of an object" error. Here is my
code again> I have trimmed it down a bit so I can just
concentrate on this one thing. Take a look if you
would please.
My VB code:


Imports System.Data.SqlClient
Imports System.Data
Public Class Home
Inherits System.Web.UI.Page
Protected WithEvents TestRepeater As
System.Web.UI.WebControls.Repeater
Protected WithEvents DD_InsurPayAction As
System.Web.UI.WebControls.DropDownList
Protected MyConnect As SqlConnection
Protected oreader As SqlDataReader
#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
MyBase.Init
'CODEGEN: This method call is required by the
Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
Dim ConnectString As String
MyConnect = New SqlConnection()
ConnectString =
ConfigurationSettings.AppSettings("ConnectStr")
MyConnect.ConnectionString = ConnectString
If Not IsPostBack Then
BindGrid()
End If
End Sub
Protected Sub BindGrid()
MyConnect.Open()
Dim strSQL As String = "Select * from users"
Dim MyCommand As SqlDataAdapter = New
SqlDataAdapter(strSQL, MyConnect)
Dim UserDS As DataSet = New DataSet()
MyCommand.Fill(UserDS, "Users")
TestRepeater.DataSource = UserDS
TestRepeater.DataBind()
MyConnect.Close()
End Sub

'Protected Sub InsurDropDown()
' Dim AddChoice As ListItem
' Dim MyCommand = New SqlCommand("Select * From
Items", MyConnect)
' oreader = MyCommand.ExecuteReader()
' DD_InsurPayAction.DataSource = oreader
' DD_InsurPayAction.DataBind()
' oreader.Close()
' AddChoice = New ListItem("Select Action", "0")
' AddChoice.Selected = True
' If Not
DD_InsurPayAction.Items.Contains(AddChoice) Then
' DD_InsurPayAction.Items.Insert(0, AddChoice)
' End If
'End Sub

Protected Sub AttachDropdowns(ByVal S As Object,
ByVal e As RepeaterItemEventArgs)
Dim InsurDD As dropdownlist  =
e.Item.FindControl("DD_InsurPayAction")

Dim AddChoice As ListItem
Dim MyCommand = New SqlCommand("Select * From
Items", MyConnect)
oreader = MyCommand.ExecuteReader()
InsurDD.DataSource = oreader
InsurDD.DataBind()
oreader.Close()
AddChoice = New ListItem("Select Action", "0")
AddChoice.Selected = True
If Not InsurDD.Items.Contains(AddChoice) Then
InsurDD.Items.Insert(0, AddChoice)
End If
End Sub

End Class

Here is my HTML:

<%@ Page Language="VB" ContentType="text/html"
ResponseEncoding="iso-8859-1"
CodeBehind="Home.aspx.vb" AutoEventWireup="false"
Inherits="TQSPM.Home" %>
<HTML>
<HEAD>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</HEAD>
<body>
Repeater test
<asp:repeater id="TestRepeater" Runat="server"
OnItemDataBound="AttachDropdowns">
<HeaderTemplate>
<table width="50%">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem,
"First_Name")%></td>
<td><%# DataBinder.Eval(Container.DataItem,
"Last_Name")%></td>
<td><%# DataBinder.Eval(Container.DataItem,
"UserName")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td colspan="3" align="middle">
<asp:dropdownlist ID="DD_InsurPayAction"
DataSource=<%# oreader%> Font-Size="8"
runat="server"></asp:dropdownlist>
</td>
</tr>
</table>
</FooterTemplate>
</asp:repeater>
</body>
</HTML>

Share: 

 

This Question has 9 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Dropdown nested in repeater Or get search suggestion and latest updates.


Tagged: