Drop down list inside a repeater

Discussion in 'ASP .Net' started by Guest, Dec 4, 2003.

  1. Guest

    Guest 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.
    Guest, Dec 4, 2003
    #1
    1. Advertising

  2. Guest

    Goncalo Guest

    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

    >-----Original Message-----
    >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.
    >.
    >
    Goncalo, Dec 5, 2003
    #2
    1. Advertising

  3. Guest

    Hatim R Guest

    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

    <> wrote in message
    news:cf4e01c3ba82$1bb271a0$...
    > 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.
    Hatim R, Dec 5, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SirPoonga
    Replies:
    2
    Views:
    742
    Ben Strackany
    Jan 7, 2005
  2. weiwei
    Replies:
    0
    Views:
    1,001
    weiwei
    Jan 5, 2007
  3. Replies:
    1
    Views:
    392
  4. msimmons
    Replies:
    0
    Views:
    458
    msimmons
    Jul 16, 2009
  5. Replies:
    5
    Views:
    252
Loading...

Share This Page