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: Ralph Murray   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.

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: