Complex databinding with ASP Listbox

R

Ray Valenti

I have a ASP listbox that I am trying to populate with two fields, one for
display (Category) and one to store (ID) as the selected item. I can
successfully populate and view the list. How ever after specifying the
field to hold the selected value with the Databindings property, the error
below show up.

VS changes the DataSource from DSMain1 to the expression:
DataBinder.Eval(dsMain1, "Tables[Links].DefaultView.[0].fkeyCategory")

Can I bind to both the list source (two fields) and a field that holds the
selected value at the same time?

-Ray

---- error
returned -------------------------------------------------------------------
--------------------
An invalid data source is being used for lstCategory. A valid data source
must implement either IListSource or IEnumerable.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.ArgumentException: An invalid data source is being
used for lstCategory. A valid data source must implement either IListSource
or IEnumerable.

Source Error:


Line 63: <TD><asp:textbox id=txtExpirationDate runat="server" Text='<%#
DataBinder.Eval(dsMain1, "Tables[Links].DefaultView.[0].ExpirationDate")
%>'></asp:textbox></TD>
Line 64: <TD></TD>
Line 65: <TD rowSpan="4"><asp:listbox id=lstCategory runat="server"
DataValueField="ID" DataTextField="Category" DataMember="Category"
DataSource='<%# DataBinder.Eval(dsMain1,
"Tables[Links].DefaultView.[0].fkeyCategory") %>' Width="150px"
Height="130px"></asp:listbox></TD>
Line 66: </TR>
Line 67: <TR>


Source File: c:\inetpub\wwwroot\Quixor\links\LinkAdd.aspx Line: 65
 
E

evolve

as far as i'm aware there is the listindex
which is just 0,1,2,3,4,5,....
there is the text that you see and there is the
value that you don't see but can read
selecteditem.value
as i recall

in the properties window
dataTextField - what you want to see
dataValueField - the useful info field

then just access it dropdownlist.selecteditem.value

if not then i guess you could always delimit a field and slap it in the
value field


Ray Valenti said:
I have a ASP listbox that I am trying to populate with two fields, one for
display (Category) and one to store (ID) as the selected item. I can
successfully populate and view the list. How ever after specifying the
field to hold the selected value with the Databindings property, the error
below show up.

VS changes the DataSource from DSMain1 to the expression:
DataBinder.Eval(dsMain1, "Tables[Links].DefaultView.[0].fkeyCategory")

Can I bind to both the list source (two fields) and a field that holds the
selected value at the same time?

-Ray

---- error
returned -------------------------------------------------------------------
--------------------
An invalid data source is being used for lstCategory. A valid data source
must implement either IListSource or IEnumerable.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.ArgumentException: An invalid data source is being
used for lstCategory. A valid data source must implement either IListSource
or IEnumerable.

Source Error:


Line 63: <TD><asp:textbox id=txtExpirationDate runat="server" Text='<%#
DataBinder.Eval(dsMain1, "Tables[Links].DefaultView.[0].ExpirationDate")
%>'></asp:textbox></TD>
Line 64: <TD></TD>
Line 65: <TD rowSpan="4"><asp:listbox id=lstCategory runat="server"
DataValueField="ID" DataTextField="Category" DataMember="Category"
DataSource='<%# DataBinder.Eval(dsMain1,
"Tables[Links].DefaultView.[0].fkeyCategory") %>' Width="150px"
Height="130px"></asp:listbox></TD>
Line 66: </TR>
Line 67: <TR>


Source File: c:\inetpub\wwwroot\Quixor\links\LinkAdd.aspx Line: 65
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top