Binding data to a server control inside repeator control

M

muthu

Hi guys,

Iam using a repeator control in my page.In wich i have
dropdown list as the last column.I have a label in the first
column.Now i have binded a datable to the repeator in the page load
event.And assigned vale to the label in html as

<asp:Label ID="c_invAmt" Runat="server" cssclass="smcsAmountLabel">
<%# DataBinder.Eval(Container.DataItem,"InvoiceAmount") %>
</asp:Label>


Now i want to bind data to the dropdown list in the last column.I have
a function that returns a datatable.

I tried to bind the dropdown in html as follows

<asp:DropDownList ID="c_currencyList" Runat="server" Visible="False"
DataSource='<%=GetCurrencies()%>' DataTextField="XXX"
DataValueField="XXX">
</asp:DropDownList>

But it throws an error saying

The datasource property is set only by the run time.It cannot be
declared.

So i tried to bind the dropdown list in the itemdatabound event of the
repeator.But the data is not binded to the dropdown list.

How can i achieve that.Can any one help me out...........
 
G

Guest

The error says you can't bind the data like you are doing, i.e.
declaratively, you can only do it at runtime. So do it at runtime instead.

E.G. Don't do this:

DataSource='<%=GetCurrencies()%>'

Put something like this in you pageload event

if (!IsPostBack)
{
c_currencyList.DataSource = SomeDataSourceObject;
c_currencyList.DataBind();
}
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top