Sunday, 10 July 2011

repeater inside repeater and dropdown list

IDStateCityrepeaterdropdown
3upkanpur
IDStateCity
3upkanpur
3upluchnow
3upagra
3upjhansi
6mpjabalpur
6mpujjain
6mpbhopal
3upluchnow
IDStateCity
3upkanpur
3upluchnow
3upagra
3upjhansi
6mpjabalpur
6mpujjain
6mpbhopal
3upagra
IDStateCity
3upkanpur
3upluchnow
3upagra
3upjhansi
6mpjabalpur
6mpujjain
6mpbhopal
3upjhansi
IDStateCity
3upkanpur
3upluchnow
3upagra
3upjhansi
6mpjabalpur
6mpujjain
6mpbhopal
6mpjabalpur
IDStateCity
3upkanpur
3upluchnow
3upagra
3upjhansi
6mpjabalpur
6mpujjain
6mpbhopal
6mpujjain
IDStateCity
3upkanpur
3upluchnow
3upagra
3upjhansi
6mpjabalpur
6mpujjain
6mpbhopal
6mpbhopal
IDStateCity
3upkanpur
3upluchnow
3upagra
3upjhansi
6mpjabalpur
6mpujjain
6mpbhopal



repeater control inside repeater and drop downlist

html code-


<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
  
    </div>
    <asp:Repeater ID="Repeater1" runat="server">
    <HeaderTemplate>
    <table border="1" cellpadding="2" cellspacing="1" width="600px">
    <tr bgcolor="white">
    <th>ID</th>  
    <th>State</th>
    <th>City</th>
    <th>repeater</th>
    <th>dropdown</th>
    </tr>  
     </HeaderTemplate>
     <ItemTemplate>
     <tr >
     <td width="100px"><%#DataBinder.Eval(Container,"dataitem.id") %></td>
     <td  width="100px"><%#DataBinder.Eval(Container,"dataitem.state") %></td>
     <td width="100px"><%#DataBinder.Eval(Container,"dataitem.city") %></td>
     <td><asp:Repeater ID="sd" runat="server" DataSource='<%# mukesh()%>' >
    

     <HeaderTemplate>
  
     <table border="1" width="200px" cellpadding="1" cellspacing="1">
     <tr bgcolor="maroon" >
    <th>ID</th>  
    <th>State</th>
    <th>City</th>
        </tr>
  
     </HeaderTemplate>
     <ItemTemplate>
     <tr >
     <td width="100px"><%#DataBinder.Eval(Container,"dataitem.id") %></td>
     <td  width="100px"><%#DataBinder.Eval(Container,"dataitem.state") %></td>
     <td width="100px"><%#DataBinder.Eval(Container,"dataitem.city") %></td>
  
     </ItemTemplate>
  
     <FooterTemplate>
     </table>
     </FooterTemplate>
  
  
  
     </asp:Repeater></td>
     <td><asp:DropDownList ID="pl" runat="server" DataSource='<%#mukesh() %>'  DataTextField="city" ></asp:DropDownList>
</td>
     </tr>
  
     </ItemTemplate>
  
  
    <FooterTemplate>
  
    </table>
    </FooterTemplate>
  
 
  
    </asp:Repeater>
    </form>
</body>
</html>

.aspx code


using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page 
{

    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString);
    SqlCommand cmd = new SqlCommand();
    protected void Page_Load(object sender, EventArgs e)
    {
        cmd.Connection = con;
        if (!IsPostBack == true)
        {
            Repeater1.DataSource = mukesh();
            Repeater1.DataBind();
        }
        else
        {
            Response.Write("not post back");
        }
    }

    public DataSet mukesh()
    {
        SqlDataAdapter da = new SqlDataAdapter("select * from emp23", con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        return ds;
    }
}