Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

Dropdown nested in repeater

  Asked By: Zobah    Date: Dec 18    Category: Asp.net    Views: 2280
  

I'm try to include three drop downs in a repeater. I
think I have it half way there and need some help
wrapping it up. My drop downs are in my footer
template and below I have included my sub routines
that I am using to populate my dropdowns.


Protected Sub InsurDropDown()
MyConnect.Open()
Dim AddChoice As ListItem
Dim MyCommand = New SqlCommand("Select * From
tCollectionAction where Type = 1 or Type = 0",
MyConnect)
oReader = MyCommand.ExecuteReader()
DD_InsurPayAction.DataSource = oReader
DD_InsurPayAction.DataBind()
MyConnect.Close()
AddChoice = New ListItem("Select Insurance
Payment 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 InusurDD As DropDownList =
e.Item.FindControl("DD_InsurPayAction")
Dim PatientDD As DropDownList =
e.Item.FindControl("DD_PatPayAction")
Dim CoPayDD As DropDownList =
e.Item.FindControl("DD_CoPayAction")
InsurDropDown()
PatientDropDown()
CoPayDropDown()
End Sub

Share: 

 

10 Answers Found

 
Answer #1    Answered By: Devrim Yilmaz     Answered On: Dec 18

Can anyone help me out here. I am kind of under the
gun with getting over this little hump.

 
Answer #2    Answered By: Ella Brown     Answered On: Dec 18

Could you send more code? Also - it'd help to know what's currently
happening -- any errors or is the page not writing expected values?

 
Answer #3    Answered By: Liam Bouchard     Answered On: Dec 18

Yes, the error that I am getting when the page first
loads is this:
Object reference not set to an instance of an object.

Also here is a more complete code set.


Protected 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
'Lbl_Biller.Text =
Convert.ToString(Session("UserCode"))
If Not IsPostBack Then
BindGrid()
Collections()
Else

End If
End Sub

Protected Sub BindGrid()
Dim strSQL As String = "Select top 5 * From
vCollectionQForms" & _
" Where DOS is not
null" & _
" or Priority is not
null" & _
" or Status is not null
Order by Priority asc"
Dim MyCommand As SqlDataAdapter = New
SqlDataAdapter(strSQL, MyConnect)
Dim CollectionQDS As DataSet = New DataSet()
MyCommand.Fill(CollectionQDS, "CollectionQ")
CollectionQDataGrid.DataSource = CollectionQDS
CollectionQDataGrid.DataBind()
Dim Row1 As DataRow =
CollectionQDS.Tables("CollectionQ").Rows(0)
Lbl_AccountNum.Text =
Row1("ACCOUNTNUM").ToString()
Lbl_DOS.Text = Format(Row1("DOS"),
"d").ToString()
Lbl_PatientName.Text =
Row1("PatientName").ToString()
Lbl_Priority.Text =
Row1("Priority").ToString()
Lbl_TodayStatus.Text =
Row1("Status").ToString()
Lbl_PatientAge.Text = Row1("Age").ToString()
Lbl_ResponsParty.Text =
Row1("Subscriber").ToString()
Lbl_PrimaryInsure.Text =
Row1("CarrierNam").ToString()
'Lbl_SecInsure.Text =
Row1("PayorName").ToString()
End Sub

Protected Sub Collections()
MyConnect.Open()
Dim strSQL As String = "Select *,
QTY1*CHARGES1 As StdFee," & _
"AllowableAmt - insurancepaid As InsureVar "
& _
"from tCollectionQ " & _
"where ACCOUNTNUM = " & _
Lbl_AccountNum.Text & "and DOS='" &
Lbl_DOS.Text & "'"
Dim objAdapter As SqlDataAdapter = New
SqlDataAdapter(strSQL, MyConnect)
Dim CollectionQDS As DataSet = New DataSet()
objAdapter.Fill(CollectionQDS,
"CollectionQinfo")
Dim dRow As DataRow =
CollectionQDS.Tables("CollectionQinfo").Rows(0)
CollectionsTable.DataSource =
CollectionQDS
CollectionsTable.DataBind()


Dim SQLCommand As New SqlCommand(strSQL,
MyConnect)
Dim SQLReader = SQLCommand.ExecuteReader()
CollectionsTable.DataSource = SQLReader
CollectionsTable.DataBind()
SQLReader.close()
MyConnect.Close()
End Sub

Protected Sub InsurDropDown()
'MyConnect.Open()
Dim AddChoice As ListItem
Dim MyCommand = New SqlCommand("Select * From
tCollectionAction where Type = 1 or Type = 0",
MyConnect)
oReader = MyCommand.ExecuteReader()
DD_InsurPayAction.DataSource = oReader
DD_InsurPayAction.DataBind()
MyConnect.Close()
AddChoice = New ListItem("Select Insurance
Payment 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 PatientDropDown()
MyConnect.Open()
Dim AddChoice As ListItem
Dim MyCommand = New SqlCommand("Select * From
tCollectionAction where Type = 2 or Type = 0",
MyConnect)
oReader = MyCommand.ExecuteReader()
DD_PatPayAction.DataSource = oReader
DD_PatPayAction.DataBind()
MyConnect.Close()
AddChoice = New ListItem("Select Patient
Payment Action", "0")
AddChoice.Selected = True
If Not
DD_PatPayAction.Items.Contains(AddChoice) Then
DD_PatPayAction.Items.Insert(0, AddChoice)
End If
End Sub

Protected Sub CoPayDropDown()
MyConnect.Open()
Dim AddChoice As ListItem
Dim MyCommand = New SqlCommand("Select * From
tCollectionAction where Type = 3 or Type = 0",
MyConnect)
oReader = MyCommand.ExecuteReader()
DD_CoPayAction.DataSource = oReader
DD_CoPayAction.DataBind()
MyConnect.Close()
AddChoice = New ListItem("Select Co-Payment
Action", "0")
AddChoice.Selected = True
If Not
DD_CoPayAction.Items.Contains(AddChoice) Then
DD_CoPayAction.Items.Insert(0, AddChoice)
End If
End Sub

Protected Sub Btn_Save_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Dim Adapter As SqlDataAdapter = New
SqlDataAdapter()
Dim EditCB As SqlCommandBuilder
Dim EditDS As DataSet = New DataSet()
Dim Row As DataRow
ConnectString =
ConfigurationSettings.AppSettings("ConnectStr")
MyConnect.ConnectionString = ConnectString
Adapter.SelectCommand = New SqlCommand("Select
* from tCollectionCurrent where AcctNum = " & _
Lbl_AccountNum.Text & " and DOS =
'" & Lbl_DOS.Text & "'", MyConnect)
EditCB = New SqlCommandBuilder(Adapter)
Adapter.Fill(EditDS, "CurrentCollection")

Row =
EditDS.Tables("CurrentCollection").Rows(0)

Row.Item("AcctNum") = Lbl_AccountNum.Text
Row.Item("DOS") = Lbl_DOS.Text
Row.Item("Status") = "2"
Row.Item("Priority") = "B"
Row.Item("InsuranceStatus") =
DD_InsurPayAction.SelectedItem.Value
Row.Item("PatientPmtStatus") =
DD_PatPayAction.SelectedItem.Value
Row.Item("CoPayStatus") =
DD_CoPayAction.SelectedItem.Value
Adapter.Update(EditDS, "CurrentCollection")

If EditDS.HasErrors Then
Lbl_Message.Text = "There was an error
Updating Current History Information, Please try
again." & _

EditDS.Tables("GetUser").Rows(0).RowError
Else
BindGrid()
Collections()
WriteCollectionHistory()

End If
End Sub

Sub WriteCollectionHistory()
Dim CollectionHistoryDS As DataSet = New
DataSet()
Dim CollectionHistoryCB As SqlCommandBuilder
Dim ConnectString As String
Dim Connect As SqlConnection = New
SqlConnection()
Dim Adapter As SqlDataAdapter = New
SqlDataAdapter()
Dim Row As DataRow
ConnectString =
ConfigurationSettings.AppSettings("ConnectStr")
Connect.ConnectionString = ConnectString
Adapter.SelectCommand = New SqlCommand("Select
* from tCollectionHistory", Connect)
CollectionHistoryCB = New
SqlCommandBuilder(Adapter)
Adapter.Fill(CollectionHistoryDS,
"CollectionHistory")
Row =
CollectionHistoryDS.Tables("CollectionHistory").NewRow
Row.Item("AcctNum") = Lbl_AccountNum.Text
Row.Item("DOS") = Lbl_DOS.Text
Row.Item("TranDate") = Now()
Row.Item("UserID") =
Convert.ToString(Session("UserCode"))
Row.Item("Status") = "2"
Row.Item("Priority") = "B"
Row.Item("InsuranceDD") =
DD_InsurPayAction.SelectedItem.Value
Row.Item("PatientDD") =
DD_PatPayAction.SelectedItem.Value
Row.Item("CoPayDD") =
DD_CoPayAction.SelectedItem.Value

CollectionHistoryDS.Tables("CollectionHistory").Rows.Add(Row)
Adapter.Update(CollectionHistoryDS,
"CollectionHistory")
If CollectionHistoryDS.HasErrors Then
Lbl_Message.Text = "There was an error
inserting Collection History Record." & _

CollectionHistoryDS.Tables("CollectionHistory").Rows(0).RowError
End If
End Sub

Protected Sub AttachDropdowns(ByVal S As Object,
ByVal e As RepeaterItemEventArgs)
'Dim InusurDD As dropdownlist  =
e.Item.FindControl("DD_InsurPayAction")
'Dim PatientDD As DropDownList =
e.Item.FindControl("DD_PatPayAction")
'Dim CoPayDD As DropDownList =
e.Item.FindControl("DD_CoPayAction")
InsurDropDown()
PatientDropDown()
CoPayDropDown()
End Sub

Here is my HTML and Web Controls for the footer in the
repeater:

<FooterTemplate>
<tr>
<td align="right" colspan="4">
<asp:button id="Btn_Save"
onclick="Btn_Save_Click" Runat="server"
Text="Save"></asp:button></td>
<td colspan="3" align="middle">
<asp:dropdownlist ID="DD_InsurPayAction"
Font-Size="8" DataValueField="BillingActionID"
DataTextField="BillingActionDescription"
runat="server" /></td>
<td colspan="3" align="middle">
<asp:dropdownlist ID="DD_PatPayAction"
Font-Size="8" DataValueField="BillingActionID"
DataTextField="BillingActionDescription"
runat="server" /></td>
<td colspan="3" align="middle">
<asp:dropdownlist ID="DD_CoPayAction"
Font-Size="8" DataValueField="BillingActionID"
DataTextField="BillingActionDescription"
runat="server" /></td>
</tr>
</table>
</FooterTemplate>
</asp:repeater>

 
Answer #4    Answered By: Hababah Younis     Answered On: Dec 18

The problem is this ::

You have multiple (since it is muliplied by the repeater) control instances with
the same ID, i.e. your dropdowns.

It is a bit confusing because the repeater  does not suffer these problems as it
uses UniqueID for itself and its child controls.

If you don't databind the dropdowns it will work fine ... proving that the
multiple id problem is NOT due to the repeater.

The problem arises because you have to databind, and when you do your code
behind says there are multiple instances of your dropdowns, because it is not
within the repeater and not using the repeaters inner working to do the binding.

The answer is simple really. To do it this way (i.e. using html and aspx files)
you need to use the workings of the repeater ... so you have to databind within
the repeater.


Protected Sub InsurDropDown()
'MyConnect.Open()
Dim AddChoice As ListItem
Dim MyCommand = New SqlCommand("Select * From
tCollectionAction where type  = 1 or Type = 0",
MyConnect)
oReader = MyCommand.ExecuteReader()
DD_InsurPayAction.DataSource = oReader
DD_InsurPayAction.DataBind()
MyConnect.Close()
AddChoice = New ListItem("Select Insurance
Payment Action", "0")
AddChoice.Selected = True
If Not
DD_InsurPayAction.Items.Contains(AddChoice) Then
DD_InsurPayAction.Items.Insert(0,
AddChoice)
End If
End Sub

Here .... this is OK ... but if you try to databind to oReader your dropdowns
won't see it ... you need to make a declaration of oReader at the top (page
scope).

now ... the VITAL bit .... && easy really

<asp:dropdownlist ID="DD_InsurPayAction" Font-Size="8"
DataValueField="BillingActionID" DataTextField="BillingActionDescription"
runat="server" />

change to
<asp:dropdownlist ID="DD_InsurPayAction" Font-Size="8" datasource='<%# oReader
%> runat="server" />

or you could use a helper function that returns the datasource
<asp:dropdownlist ID="DD_InsurPayAction" Font-Size="8" datasource='<%#
GetSource("DD_InsurPayAction") %> runat="server" />

public DataSet GetSource(string s){
if (s == "DD_InsurPayAction") {
..... do all your biz
and return a dataset or dataview or whatever oReader returns or whatever
BillingActionID is ??
}
}

You'll have to sort out what does get returned yourself .... but the following
works.

--------------------------------------------------------------------------------\
---------------------------------

<asp:Repeater id="Repeater1" runat="server">
<HeaderTemplate>
helo
</HeaderTemplate>
<ItemTemplate>
Order Date: <%# DataBinder.Eval(Container.DataItem, "DateTimeValue",
"{0:d}") %>
Quantity: <%# DataBinder.Eval(Container.DataItem, "IntegerValue", "{0:N2}") %>
Item: <%# DataBinder.Eval(Container.DataItem, "StringValue") %>
Order Date: <asp:CheckBox id=chk1 Checked='<%#
(bool)DataBinder.Eval(Container.DataItem, "BoolValue") %>' runat=server/>
<asp:DropDownList id="Dropdownlist1" datasource='<%# getSrc() %>'
runat="server"></asp:DropDownList>
<br><br>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
--------------------------------------------------------------------------------\
---------------------------------
protected System.Web.UI.WebControls.Repeater Repeater1;
protected System.Web.UI.WebControls.DropDownList DropDown1;
private ArrayList values;

void Page_Load(object Sender, System.EventArgs e)
{

if (!Page.IsPostBack)
{
values = new ArrayList();

values.Add ("IN");
values.Add ("KS");
values.Add ("MD");
values.Add ("MI");
values.Add ("OR");
values.Add ("TN");


DataTable dt = new DataTable();
DataRow dr;

dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
dt.Columns.Add(new DataColumn("StringValue", typeof(string)));
dt.Columns.Add(new DataColumn("DateTimeValue", typeof(DateTime)));
dt.Columns.Add(new DataColumn("BoolValue", typeof(bool)));

for (int i = 0; i < 9; i++)
{

dr = dt.NewRow();

dr[0] = i;
dr[1] = "Item " + i.ToString();
dr[2] = DateTime.Now;
dr[3] = (i % 2 != 0) ? true : false;

dt.Rows.Add(dr);
}

Repeater1.DataSource = new DataView(dt);
Repeater1.DataBind();
}
}

public ArrayList getSrc()
{
return values;
}



Note there are better ways to do this using ITemplate and CustomControls.

 
Answer #5    Answered By: Edfu Massri     Answered On: Dec 18

Another question I have
is: Is it ok for to place my dropdown  box in the
footertemplate? I only want the drop  down to appear in
the last row of the table. I notice that in the sample
code that you sent me the drop down in placed in the
itemtemplate. What are your thoughts on this?

 
Answer #6    Answered By: Samuel Costa     Answered On: Dec 18

From looking at the code - it seems that eveything's good. I have a few
ideas - but they could be the jus tresult of trying to piece together the
fragments of code...

* is the AttachDropdowns function executing? i didn't notice any
event-wiring code to tell it to run (like Handles Repeater1.ItemDataBound)
* are your drop  downs declared locally in the code-behind? like:
protected DD_InsurPayAction as DropDownList
the reason i ask is that i noticed the command:
Dim InusurDD As DropDownList =
e.Item.FindControl("DD_InsurPayAction")
in AttachDropdowns() and didn't know why you'd reference
DD_InsurPayAction in that way (although in other functions i see you
reference it directly as a class member)

If both of these are working - then which line is it that's throwing the
error?

 
Answer #7    Answered By: Dirck Jansen     Answered On: Dec 18

Sure can ( I diid try it but thought I'd put it there as it was more impressive
to repeate it with the items), and no problem with different data sources for
all dropdowns, item  or footer (well obviously they have to be the same per row)
. I know thats been a bit of a headache for you, I read it earlier but thought
you'd got it sorted. I didn't actually know myself untill this afternoon, I had
downloaded something from MSDN from ages ago but had never gone through it - so
it did me some good too.

 
Answer #8    Answered By: Calais Bernard     Answered 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>

 
Answer #9    Answered By: Calvin Banks     Answered On: Dec 18

The problem now is that SQLDataReader doesn't return a dataset ... it merelt
reads etc.

I found this
ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpcontheadonetdatareader.htm

While a DataReader is open, you can retrieve schema information about the
current result set using the GetSchemaTable method. GetSchemaTable returns a
DataTable object  populated with rows and columns that contain the schema
information for the current result set.


[C#]


DataTable schemaTable = myReader.GetSchemaTable();

foreach (DataRow myRow in schemaTable.Rows)
{
foreach (DataColumn myCol in schemaTable.Columns)
Console.WriteLine(myCol.ColumnName + " = " + myRow[myCol]);
Console.WriteLine();
}

So try

DataTable oReadDT = oReader.GetSchemaTable();

and set your dataSource to oReadDT

 
Answer #10    Answered By: Ralph Murray     Answered On: Dec 18

You have declared your reader

Protected oreader As SqlDataReader
-------------------------------------------------------------------
You have 1 dropdown


<asp:dropdownlist ID="DD_InsurPayAction"
DataSource=<%# oreader%> Font-Size="8"
runat="server"></asp:dropdownlist>

-------------------------------------------------------------------
Yet you have commented out your code that refers to it

'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

-------------------------------------------------------------------
And have left this is to attempt to bind to it by setting oreader : and then
immediately setting InsureDD to oreader when InsurDD no longer exists ???????
On top of this you are trying to find your control by asking for
"DD_InsurePayAction" when we have already decided that the repeater  multiplies
the ID and thus screws things up. So you cannot use FindControl() in this
instance.
{{{{ There may be away to get inside the repeater and to its child controls by
genearting the id's that the repeater uses for its child controls, I nearly got
there once but ended up being diverted. The repeater will generate ID's for
"DD_InsurePayAction" and they will look something like
"DD_InsurePayAction_ctl0__ctl3" ... that would be the other way to do it ....
but this way is neater }}}}}

I would get rid of this completely for now, try to work it back in later.
So get rid of this for now.
Instead ... if you need modify what is returned from datareader, then do it in
DataTable version of MyDataSource() ( see further down).
You can pick the bits you want out of the DataTable and return just those bits.


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

-------------------------------------------------------------------
-------------------------------------------------------------------

Try something like this


<asp:dropdownlist ID="DD_InsurPayAction"
DataSource=<%# MyDataSource()%> Font-Size="8"
runat="server"></asp:dropdownlist>

Then in your code behind ( I know, I know, function declaration - I'm a sharper,
soz)

DataReader MyDataSource()
{
Dim oreader As SqlDataReader
Dim MyCommand = New SqlCommand("Select * From Items", MyConnect)
oreader = MyCommand.ExecuteReader()
return oreader
}


OR

DataTable MyDataSource()
{
Dim oreader As SqlDataReader
Dim MyCommand = New SqlCommand("Select * From Items", MyConnect)
oreader = MyCommand.ExecuteReader()
Dim oReadDT As DataTable = myReader.GetSchemaTable()
return oReadDT
}


Just switch between your combos in MyDataSource

-------------------------------------------------------------------

Actually I've just got out of bed and turned the 'puter on ... a bit later I'll
try something along these lines datareader and post it.
I can't do it right now because I have no SQLServer ( I think I have slammer
virus) but let me fix that, and stick my head under the tap and gargle with some
toothpaste and I'll have ago.

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




Tagged: