Drop down list inside a repeater

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I'm trying to have a drop down list inside a repeater
where the data for the list is extracted from a database
along with other items but I can't seem to get it to work
for the list.

My html is as follows:
<asp:panel id="Panel1" style="Z-INDEX: 104; LEFT: 240px;
POSITION: absolute; TOP: 184px" runat="server"
Height="386px" Width="594px">
<asp:Repeater id="TaskRepeater" runat="server">
<HeaderTemplate>
<table border="0" width="594">
<tr>
<td align="left">Task</td>
<td align="left">Project</td>
<td align="left">Language</td>
<td align="center">Progress</td>
<td align="left">Wordcount</td>
<td align="left">Assignee</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td width="150">
<%# DataBinder.Eval(Container.DataItem,"TASK_NAME") %>
</td>
<td width="150">
<%# DataBinder.Eval(Container.DataItem,"PROJECT_NAME") %>
</td>
<td width="150">
<asp:DropDownList id="LanguageDropDownList"
DataTextField="LANG_NAME"
style="Z-INDEX: 101; LEFT: 205px; POSITION: absolute; TOP:
30px"
runat="server" Height="18px"
Width="74px"></asp:DropDownList>


What's happening is that I get TASK_NAME,PROJECT_NAME out
ok (although they are repeated for each LANG_NAME) but I
cannot get anything for LANG_NAME. I know that LANG_NAME
is being extracted correctly from the database since if I
exchange PROJECT_NAME for LANG_NAME in the code above then
I get the languages ok.

I can't find much info./samples on this type of thing -
can anyone help?

Thanks in advance.
 
I did what you are trying to do binding the dropdownlist
with another datatable, not with the data that the
repeater is binded with.

To do this I overwrited the repeater method
onItemDataBound for the corresponding event.

Important: If you just want to bind the dropdownlist, this
works, but with you want to do something like select an
item you will have some trouble.

By this moment that's all I can say about this subject...

good luck
Goncalo
 
Hi Rona,

here is a way of doing it you can catch the event ItemDataBound so you would
have a line of code like this
this.TaskRepeater.ItemDataBound += new
System.Web.UI.WebControls.RepeaterItemEventHandler(this.TaskRepeater_ItemBou
nd);

and then in the you would have to add the method below

private void DataGrid1_ItemBound(object sender, DataGridItemEventArgs e){

if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem){

DropDownList =
(DropDownList)e.Item.FindControl("LanguageDropDownList");

//here you loop trough the languages to add them
somthing similar to this

DropDownList.Items.Add(new ListItem("name","value"));

}

}



the code above isn't tested or compiled i just wrote it of the top of my
head maybe if you provide more about how you bind the repeater to the
database I would be able to give you more details.

Cheers

Tim
 
Back
Top