Logo 
Search:

Asp.net Forum

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

Dropdown nested in repeater

  Asked By: Mona    Date: Nov 29    Category: Asp.net    Views: 2399
  

What you want to do cannot be done. Firstly repeater is cr*p so I took it up a
gear to a datalist.

The reason is this

private void list_SelectedIndexChanged(object sender, System.EventArgs e)

as opposed to
public void List_Update(Object sender, DataListCommandEventArgs e)
The first one is the event fired when the row of a datalist is selected, the
second is the event fired when the row of a datalist in edit mode is updated.

NOTE :: it can be done if list is in edit mode.

You need the DataListCommanEventArgs to get to the controls within the repeater.
When you click the repeater(or datalist) you don't actually get the control
within because you have no DataListCommandEventArgs, you get the datakey- and
work from that.

I can get the combo into the datalist, and get them filled with the correct
data, but I cannot get to their selectedIndexChanged handler.

I have also done some jazzy footwork and tries to mimick the child controls
creation, and assign id's, etc, but it still doesn't want to do it even though
they have id's now(even though it really, really should the way I have done it)

I'll battle on and travel every possible venue.

Share: 

 

7 Answers Found

 
Answer #1    Answered By: Adel Fischer     Answered On: Nov 29

I finally nailed it last night or should I say early
this morning. I don't have the code with me right now
but I will post it so you can see what I did to get it
to work!

My next hurdle is when I hit the save button I need to
do something to capture the value and save what I have
selected to the database. If you have any thoughts on
this let me know.

 
Answer #2    Answered By: Teresa Rogers     Answered On: Nov 29

I do ...

I want to know why you want this ?

I ask because in a repeater  or a datalist  you have an edit  item template, so you
can do all your updating from there.

Why then would you want a repeater,which is really  meant for display purposes,
to include a combo  that can be altered and the data updated  ?
(and i take it you would then move on to do a textbox and every other sort of
control)

I know it would be useful, but why ? is it absolutely essential ?

I can see how it would be useful to avoid the edit item template and simply
display an updatable grid (without having to post back on the edit item button),
then hit a save button and save everything you've changed. A bit like you can
with a Windows Form.

But even if you did get this far you would probably have a save button on every
row anyway, && making a save button for the whole grid would mean zooming
through the repeater controls  and saving as you go I suppose.

Dan, Like I said, I did get some way to it, but if you've done it then

(a) I'd love to see the code
or
(b) just give me a run down, roughly of how you went about it.
&&
(c) what the final functionality you have obtained actually is.

 
Answer #3    Answered By: Tammy Sanders     Answered On: Nov 29

Sorry it has taken me a while to reply I only get to
work on this project in my spare time.

Here is a link that will show you what I did in order
to get the drop down to work inside the repeater:

www.dotnet247.com/247reference/msgs/9/46787.aspx

The reason that I am using a repeater  is so I can have
the flexiblity of a table (i.e. colspan, multiple
headers) I don't no of a way to do this with other
controls.
The drop down is the only thing that is being update
in the repeater. The reason why I wanted to put the
drop down in the repeater is so I could have the
column that held the drop down span multiple columns
and line up correctly.

The next problem that I have ran into with nesting the
drop down in the repeater is that when I click  the
save button to take what has been selected  in the drop
down and save it to the database it get this error:
Object reference not set to an instance of an object.

Here is the line of code that it errors on:
Row.Item("InsuranceStatus") =
CType(FindControl("DD_InsurPayAction"),
DropDownList).SelectedItem.Value

Any ideas?

 
Answer #4    Answered By: Hilma Miller     Answered On: Nov 29

Forget the footer for now.

Have you got dropdownlists in your item template that you are changing ?
Have you got textboxes in your item template that you are changing ?

Have you got these filled with your data ?

You say you have a save button ... does it work for the items mentioned above ?

Now to the footer, a dropdownlist in the footer, what does it do ?

If you have all the stuff working in your items, then what does the footer
dropdownlist actually do ?
If you do not have changeable data in your items, then what could footer
dropdownlist possibly achieve ?

If you do not have all the stuff in your items being saved then this would seem
a logical first step BEFORE moving onto the footer.
If you have past this stage then please post code or at least an incling of how
you went about it.

 
Answer #5    Answered By: Earl Stone     Answered On: Nov 29

I will try to explain this the best I can.
I have two sections to this page the top section
contains patients general info. The Bottom section
contains the repeater  a bunch of patient data. The
user can select different actions to take based on
what the data displays ( the data is read only). I
will paste my code below. The big problem that I am
having know is that I can't get the information that
is selected  in the drop down to save to the database.
I keep getting this crazy object referrence error. I
am stumped! Can you help. Here is my code

 
Answer #6    Answered By: Anna Hill     Answered On: Nov 29


Sub Page_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
iStdFeeTot = 0
iInsureVarTot = 0
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()
'InsurDropDown()
'PatientDropDown()
'CoPayDropDown()
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_PatientID.Text =
Row1("PatientID").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()
End Sub


Sub Collections()
Dim strSQL As String = "Select *,
QTY1*CHARGES1 As StdFee," & _
"AllowableAmt - insurancepaid As InsureVar
" & _
"from tCollectionQ " & _
"where PatientID = " & _
Lbl_PatientID.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)
For Each dRow In
CollectionQDS.Tables("CollectionQinfo").Rows
iStdFeeTot = iStdFeeTot +
CType(dRow("StdFee"), Double)
iInsureVarTot = iInsureVarTot +
CType(dRow("InsureVar"), Double)
Next

CollectionsTable.DataSource = CollectionQDS
CollectionsTable.DataBind()
Dim SQLCommand As New SqlCommand(strSQL,
MyConnect)
MyConnect.Open()
oReader =
SQLCommand.ExecuteReader(CommandBehavior.CloseConnection)
CollectionsTable.DataSource = oReader
CollectionsTable.DataBind()
MyConnect.Close()
End Sub

Sub AttachFooter(ByVal S As Object, ByVal ea As
RepeaterItemEventArgs)
If ea.Item.ItemType = ListItemType.Footer Then
' Add Totals for Columns

CType(ea.Item.FindControl("Lbl_StdFee_Total"),
Label).Text = Format(iStdFeeTot, "c")
'Populate Insurance Drop down
Dim DD_InsurPayAction As DropDownList =
CType(ea.Item.FindControl("DD_InsurPayAction"),
DropDownList)
Dim AddInsurChoice As ListItem
Dim InsurCommand = New SqlCommand("Select
* From tCollectionQAction where Type = 1 or Type = 0",
MyConnect)
MyConnect.Open()
oReader =
InsurCommand.ExecuteReader(CommandBehavior.CloseConnection)
DD_InsurPayAction.DataSource = oReader
DD_InsurPayAction.DataBind()
MyConnect.Close()
AddInsurChoice = New ListItem("Select
Insurance Payment Action", "0")
AddInsurChoice.Selected = True
If Not
DD_InsurPayAction.Items.Contains(AddInsurChoice) Then
DD_InsurPayAction.Items.Insert(0,
AddInsurChoice)
End If

'Populate Patient Drop down
Dim DD_PatPayAction As DropDownList =
CType(ea.Item.FindControl("DD_PatPayAction"),
DropDownList)
Dim AddPatChoice As ListItem
Dim PatCommand = New SqlCommand("Select *
From tCollectionQAction where Type = 2 or Type = 0",
MyConnect)
MyConnect.Open()
oReader =
PatCommand.ExecuteReader(CommandBehavior.CloseConnection)
DD_PatPayAction.DataSource = oReader
DD_PatPayAction.DataBind()
MyConnect.Close()
AddPatChoice = New ListItem("Select
Patient Payment Action", "0")
AddPatChoice.Selected = True
If Not
DD_PatPayAction.Items.Contains(AddPatChoice) Then
DD_PatPayAction.Items.Insert(0,
AddPatChoice)
End If

'Populate Co-Pay DropDown
Dim DD_CoPayAction As DropDownList =
CType(ea.Item.FindControl("DD_CoPayAction"),
DropDownList)
Dim AddCoPayChoice As ListItem
Dim CoPayCommand = New SqlCommand("Select
* From tCollectionQAction where Type = 3 or Type = 0",
MyConnect)
MyConnect.Open()
oReader =
CoPayCommand.ExecuteReader(CommandBehavior.CloseConnection)
DD_CoPayAction.DataSource = oReader
DD_CoPayAction.DataBind()
MyConnect.Close()
AddCoPayChoice = New ListItem("Select
Co-Payment Action", "0")
AddCoPayChoice.Selected = True
If Not
DD_CoPayAction.Items.Contains(AddCoPayChoice) Then
DD_CoPayAction.Items.Insert(0,
AddCoPayChoice)
End If
'Collection Totals
'Dim Lbl_StdFee_Total As Label =
CType(ea.Item.FindControl("Lbl_StdFee_Total"),
Label).Text = iStdFeeTot
End If
End Sub

Protected Sub ItemCommand(ByVal Sender As Object,
ByVal e As RepeaterCommandEventArgs)
If e.CommandName = "Btn_Save" Then
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
'MyConnect.Open()
Adapter.SelectCommand = New
SqlCommand("Select * from tCollectionQCurrent where
PatientID = " & _
Lbl_PatientID.Text & "
and DOS = '" & Lbl_DOS.Text & "'", MyConnect)
EditCB = New SqlCommandBuilder(Adapter)
Adapter.Fill(EditDS, "CurrentCollection")

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

Row.Item("PatientID") = Lbl_PatientID.Text
Row.Item("DOS") = Lbl_DOS.Text
Row.Item("Status") = "2"
Row.Item("Priority") = "B"
'Row.Item("InsuranceStatus") =
CInt(DD_InsurePayAction.selecteditem.value)
Trace.Warn("Update typename",
TypeName(FindControl("DD_InsurPayAction")))
Row.Item("InsuranceStatus") =
CType(CollectionsTable.FindControl("DD_InsurPayAction"),
DropDownList).SelectedItem.Value
'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 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 tCollectionQHistory", MyConnect)
CollectionHistoryCB = New
SqlCommandBuilder(Adapter)
Adapter.Fill(CollectionHistoryDS,
"CollectionHistory")
Row =
CollectionHistoryDS.Tables("CollectionHistory").NewRow
Row.Item("PatientID") = Lbl_PatientID.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") =
CType(FindControl("DD_InsurPayAction"),
DropDownList).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
-----------------------------------------------------
vb code:
<asp:repeater id="CollectionsTable" Runat="server"
OnItemCommand="ItemCommand"
OnItemDataBound="AttachFooter">
<HeaderTemplate>
<table width="100%" border="0" align="center">
<tr bgcolor="#660099">
<td align="middle" nowrap colspan="4"><font
color="#cc9900" size="-1"> <b>Fee
Information</b> </font></td>
<td align="middle" nowrap colspan="3"><font
color="#cc9900" size="-1"> <b>Insurance
Company</b> </font></td>
<td align="middle" nowrap colspan="3"><font
color="#cc9900" size="-1"> <b>Patient
Payment Respons.</b> </font></td>
<td align="middle" nowrap colspan="3"><font
color="#cc9900" size="-1"> <b>Patient
Co-Payment</b> </font></td>
</tr>
<tr bgcolor="#660099">
<td align="middle" nowrap><font color="#cc9900"
size="-1"> <b>CPT Code</b> </font></td>
<td align="middle" nowrap><font color="#cc9900"
size="-1"> <b>Description</b> </font></td>
<td align="middle" nowrap><font color="#cc9900"
size="-1"> <b>Std Fee</b> </font></td>
<td align="middle" nowrap><font color="#cc9900"
size="-1"> <b>Tot Allowed</b> </font></td>
<td align="middle" nowrap><font color="#cc9900"
size="-1"> <b>Est</b> </font></td>
<td align="middle" nowrap><font color="#cc9900"
size="-1"> <b>Actual Pd</b> </font></td>
<td align="middle" nowrap><font color="#cc9900"
size="-1"> <b>Variance</b> </font></td>
<td align="middle" nowrap><font color="#cc9900"
size="-1"> <b>Est</b> </font></td>
<td align="middle" nowrap><font color="#cc9900"
size="-1"> <b>Pd to Date</b> </font></td>
<td align="middle" nowrap><font color="#cc9900"
size="-1"> <b>Still Owed</b> </font></td>
<td align="middle" nowrap><font color="#cc9900"
size="-1"> <b>Est</b> </font></td>
<td align="middle" nowrap><font color="#cc9900"
size="-1"> <b>Pd to Date</b> </font></td>
<td align="middle" nowrap><font color="#cc9900"
size="-1"> <b>Still Owed</b> </font></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td align="middle" nowrap> <Font
size="-2"><%#
Container.DataItem("CODE1")%></Font> </td>
<td align="middle" nowrap> <Font
size="-2"><%#
Container.DataItem("codedescription")%></Font> </td>
<td align="middle" nowrap> <%#
format(Container.DataItem("StdFee"),"c")%> </td>
<td align="middle" nowrap> <%#
Format(Container.DataItem("AllowableAmt"),"c")%> </td>
<td align="middle" nowrap> <%#
Format(Container.DataItem("AllowableAmt"),"c")%> </td>
<td align="middle" nowrap> <%#
Format(Container.DataItem("insurancepaid"),"c")%> </td>
<td align="middle" nowrap> <%#
Format(Container.DataItem("InsureVar"),"c")%> </td>
<td align="middle" nowrap> 0 </td>
<td align="middle" nowrap> <%#
Format(Container.DataItem("patientpaid"),"c")%> </td>
<td align="middle" nowrap> 0 </td>
<td align="middle" nowrap> 0 </td>
<td align="middle" nowrap> 0 </td>
<td align="middle" nowrap> 0 </td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr bgcolor="#e5e5e5">
<td align="middle" nowrap> <font
size="-2"><%#
Container.DataItem("CODE1")%></font> </td>
<td align="left" nowrap> <font
size="-2"><%#
Container.DataItem("codedescription")%></font> </td>
<td align="middle" nowrap><%#
format(Container.DataItem("StdFee"),"c")%></td>
<td align="middle" nowrap><%#
Format(Container.DataItem("AllowableAmt"),"c")%></td>
<td align="middle" nowrap><%#
Format(Container.DataItem("AllowableAmt"),"c")%></td>
<td align="middle" nowrap><%#
Format(Container.DataItem("insurancepaid"),"c")%></td>
<td align="middle" nowrap><%#
Format(Container.DataItem("InsureVar"),"c")%></td>
<td align="middle" nowrap>0</td>
<td align="middle" nowrap><%#
Format(Container.DataItem("patientpaid"),"c")%></td>
<td align="middle" nowrap>0</td>
<td align="middle" nowrap>0</td>
<td align="middle" nowrap>0</td>
<td align="middle" nowrap>0</td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
<tr bgcolor="#e5e5e5">
<td align="right" colspan="2">Totals:</td>
<td align="middle" nowrap>
<asp:Label ID="Lbl_StdFee_Total"
Runat="server"></asp:Label>
</td>
<td align="middle" nowrap> 0 </td>
<td align="middle" nowrap> 0 </td>
<td align="middle" nowrap> 0 </td>
<td align="middle" nowrap> 0 </td>
<td align="middle" nowrap> 0 </td>
<td align="middle" nowrap> 0 </td>
<td align="middle" nowrap> 0 </td>
<td align="middle" nowrap> 0 </td>
<td align="middle" nowrap> 0 </td>
<td align="middle" nowrap> 0 </td>
</tr>
<tr>
<td align="right" colspan="4">
<asp:button CommandName="Btn_Save"
Runat="server" Text="Save"></asp:button></td>
<td colspan="3" align="middle"
bgcolor="#660099">
<asp:dropdownlist ID="DD_InsurPayAction"
Font-Size="8" DataValueField="BillingActionID"
DataTextField="BillingActionDescription"
runat="server" /></td>
<td colspan="3" align="middle"
bgcolor="#660099">
<asp:dropdownlist ID="DD_PatPayAction"
Font-Size="8" DataValueField="BillingActionID"
DataTextField="BillingActionDescription"
runat="server" /></td>
<td colspan="3" align="middle"
bgcolor="#660099">
<asp:dropdownlist ID="DD_CoPayAction"
Font-Size="8" DataValueField="BillingActionID"
DataTextField="BillingActionDescription"
runat="server" /></td>
</tr>
</table>
</FooterTemplate>
</asp:repeater>

 
Answer #7    Answered By: Alexander Fields     Answered On: Nov 29

selected  Some records from the Db into the
datareader.How can I know the Number of records
Returned.I tried all the properties But Failed.

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




Tagged: