how to add dropdownlist dynamically to a particular row dynamically in a repeater

584 views Asked by At

I want to add dropdownlist to a repeater in asp.net c#

I want to display dropdownlist of boarding points on clicking select seats like redbus.in

how to do that

<asp:Repeater ID="rptItemsInCart"
  OnItemDataBound="rptItemsInCart_ItemDataBound" runat="server"> 
<HeaderTemplate>
<table>
  <thead>
    <tr>
        <th>Service id</th>
        <th>Fare</th>
        <th>Type</th>
    </tr>
      <tr>
           <asp:Button ID="Button1" runat="server" Text="Button" />
      </tr>
  </thead>
  <tbody>
    </HeaderTemplate>
   <ItemTemplate>
     <tr>
 <td><%# Eval("serviceId") %></td>
  <td><%# Eval("fare")%></td>
  <td><%# Eval("busType")%></td>
</tr>
    </ItemTemplate>

   <FooterTemplate>
</tbody>
</table>
   </FooterTemplate>
 </asp:Repeater>
1

There are 1 answers

0
Shahul Hameed On
        SqlConnection conn = new SqlConnection(@"Data Source=SQL2008;Initial Catalog=SMS;User ID=sa;password=sql;");
        conn.Open();
        SqlCommand cmd = new SqlCommand("select *  from P1091", conn);
        SqlDataAdapter adp = new SqlDataAdapter(cmd);
        DataSet ds1 = new DataSet();
        adp.Fill(ds1);

        foreach (RepeaterItem item in rptItemsInCart.Items)
        {

            DropDownList drop = (DropDownList)item.FindControl("DropDownList1");
            drop.DataSource = ds1;
            drop.DataTextField = "P_Dent_N";
            drop.DataValueField = "P_Dent_N";
            drop.DataBind();
            drop.Items.Insert(0, new ListItem("---Select---", "0"));


        }