Friday, 30 May 2014

Redirect to another page after few second

No comments
in cs

protected void Page_Load(object sender, EventArgs e)
    {
        Response.AddHeader("REFRESH", "2;URL=login.aspx");
    }

or

 ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ScriptKey", "alert('ok');window.location='Transfer.aspx'; ", true);

mouse hover and out on linkbutton

 LinkButton1.Attributes.Add("onmouseover", "this.style.color=\"green\"");
 LinkButton1.Attributes.Add("onmouseout", "this.style.color=\"black\"");
read more

Add data from excel file to database

No comments
To show excel data in gridview

protected void btnShowExcelData_Click(object sender, EventArgs e)
    {
        string currpath = Server.MapPath("~/upload/payment.xlsx");
        string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + currpath + ";Extended Properties=Excel 12.0";

        OleDbConnection oledbConn = new OleDbConnection(connString);
        try
        {

            oledbConn.Open();


            OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Sheet1$]", oledbConn);

          
            OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
            // Pass the Select command to the adapter.
            objAdapter1.SelectCommand = cmd;
            // Create new DataSet to hold information from the worksheet.
            DataSet objDataset1 = new DataSet();
            // Fill the DataSet with the information from the worksheet.
            objAdapter1.Fill(objDataset1, "ExcelData");
            GridView1.DataSource = objDataset1;
            GridView1.DataBind();

        }
        catch (Exception ex)
        {
            lblInserted.Text = "" + ex;
        }
        finally
        {

            oledbConn.Close();
        }
    }


To insert data

protected void btnInsert_Click(object sender, EventArgs e)
    {
        GridView2.Visible = true;
        string currpath = Server.MapPath("~/upload/payment.xlsx");
        string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + currpath + ";Extended Properties=Excel 12.0";

        OleDbConnection oledbConn = new OleDbConnection(connString);


        oledbConn.Open();


        OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Sheet1$]", oledbConn);
        OleDbDataReader dr = cmd.ExecuteReader();


        while (dr.Read())
        {
          
            DataSet1TableAdapters.outstandingTableAdapter da1 = new DataSet1TableAdapters.outstandingTableAdapter();
            DataSet1.outstandingDataTable dt1 = new DataSet1.outstandingDataTable();
            DataSet1.outstandingRow dr0;
            dr0 = dt1.NewoutstandingRow();
            dr0.clientCode = dr[1].ToString();
            dr0.outstanding = dr[2].ToString().Trim();

            dr0.billValue = Convert.ToString(dr[3]);
            dr0.billcValue = dr[4].ToString();
            dr0.name = Convert.ToString(dr[5]);
            dr0.uname = Convert.ToString(dr[6]);
            dr0.EntryDateTime = Convert.ToDateTime(dr[7]);

            dt1.Rows.Add(dr0);
            lblInserted.Text = "Insetred";
            try
            {
               
                da1.Update(dt1);
            }
            catch (SqlException ex)
            {
                lblmsg.Text = "" + ex;
            }
        }
 
 
read more

Thursday, 29 May 2014

Adding rows on button click

No comments
.ASPX

<form id="form1" runat="server">
    <div>
       <asp:Panel ID="p1" runat="server">
        <asp:PlaceHolder ID="PlaceHolder1" runat="server">
            
       
        </asp:PlaceHolder>
        </asp:Panel>
        <br />
        <br />
        <asp:Button ID="btnadd" runat="server" onclick="btnadd_Click" Text="Add" />
       
    </div>
    </form>

.CS

static int number_rows = 1;
    protected void Page_Init(object sender, EventArgs e)
    {
        ViewState["RowsCount"] = number_rows    
    }
 protected void Page_Load(object sender, EventArgs e)
    {
 if (!IsPostBack)
        {
            generate_table();
        }
        else
        {
              string CtrlID = string.Empty;
         if (Request.Form["__EVENTTARGET"] != null &&
                     Request.Form["__EVENTTARGET"] != string.Empty)
            {
                generate_table();             
            }
            else
            {
                //to check which button or image button click caused the postback
                foreach (string controlID in Request.Form)
                {
                    Control objControl = Page.FindControl(controlID);
                    if (objControl is Button)
                    {
                        CtrlID = objControl.ID;
                        if (CtrlID == "btnadd")
                        {

                            //now the call will go to Button1_Click function
                        }                      
                    }
                }
            }
        }
    }
 protected void generate_table()
    {
        Panel p1 = new Panel();
        Table table = new Table();
        TableRow row,row1;
        TableCell cell,cell1;
        TextBox tb,tb1;
        Label lbl,lbl1;
        table.ID = "Table1";
        p1.ID = "p1";
        int s_rows = Convert.ToInt32(ViewState["RowsCount"].ToString());

        for (int k = 1; k <= s_rows; k++)
        {
            row = new TableRow();
            cell = new TableCell();
            row1= new TableRow();
            cell1 = new TableCell();

            tb = new TextBox();
            tb.ID = "tb_" + k;          
            tb.AutoPostBack = true;

            tb1 = new TextBox();
            tb1.ID = "tb1_" + k;
            tb1.AutoPostBack = true;

            lbl = new Label();
            lbl.ID = "lbl" + k;
            lbl.Text = "name";

            lbl1 = new Label();
            lbl1.ID = "lbl1" + k;
            lbl1.Text = "Address";

            cell.Controls.Add(lbl);
            cell.Controls.Add(tb);

            cell1.Controls.Add(lbl1);
            cell1.Controls.Add(tb1);
            tb.Style.Add(HtmlTextWriterStyle.MarginLeft, "120px");
            tb1.Style.Add(HtmlTextWriterStyle.MarginLeft, "104px");
            row.Cells.Add(cell);
            table.Rows.Add(row);

            row1.Cells.Add(cell1);
            table.Rows.Add(row1);           
        }

        PlaceHolder1.Controls.Add(table);       
    }

    protected void btnadd_Click(object sender, EventArgs e)
    {
        int new_rows_count = Convert.ToInt32(ViewState["RowsCount"]) + 1; //add one rows at a time
        ViewState["RowsCount"] = new_rows_count;
        generate_table();
        setdata();
    }
protected void setdata()
    {
        Table table = (Table)Page.FindControl("Table1");
        if (table != null)
        {

            foreach (TableRow tr in table.Rows)
            {
                foreach (TableCell tc in tr.Cells)
                {
                    foreach (Control ct in tc.Controls)
                    {
                        if (ct is TextBox)
                        {
                            ((TextBox)ct).Text = Request.Form[ct.ID];
                        }
                      
                    }
                }
            }
        }
    }

}
read more

Sunday, 11 May 2014

important design templates

No comments
read more

insert update delete in mvc

No comments
create model class

 public class Portal
    {
        public int uid
        { get; set; }
        public string fname
        { get; set; }
        public string lname
        { get; set; }
        public string email
        { get; set; }
        public string address
        { get; set; }
        public string phone
        { get; set; }
        public string company
        { get; set; }
        public string designation
        { get; set; }
    }


 create controler

using System.Web.Mvc;
using System.ComponentModel.DataAnnotations;
using firstmvc.Models;



public class TestController : Controller
    {
        StarBusEntities entity = new StarBusEntities();
        public ActionResult Index()
        {           
            return View();
        }
       
        [HttpGet]
        public ActionResult Insert()
        {
            Portal p1 = new Portal();
            return View(p1);
        }

        [HttpPost]
        public ActionResult Insert(Portal p1)
        {
            mvc_test mv = new mvc_test();
            mv.uid=  p1.uid ;
            mv.fname=p1.fname ;
            mv.lname=p1.lname;
            mv.email=p1.email ;
            entity.mvc_test.AddObject(mv);
            entity.SaveChanges();
            return View();
        }

        public ActionResult showEmp()
        {
            List<Portal> l1 = new List<Portal>();
            var data = from d in entity.mvc_test
                       select d;
            foreach (var p1 in data)
            {
                Portal mv = new Portal();
                mv.uid = p1.uid;
                mv.fname = p1.fname;
                mv.lname = p1.lname;
                mv.email = p1.email;
                l1.Add(mv);
            }
            return View(l1);
        }

        [HttpGet]
        public ActionResult Edit(int id)
        {
            var p1 = entity.mvc_test.Single(i => i.uid == id);
            Portal mv = new Portal();
            mv.uid = p1.uid;
            mv.fname = p1.fname;
            mv.lname = p1.lname;
            mv.email = p1.email;
            return View(mv);
        }
        [HttpPost]
        public ActionResult Edit(Portal p1, int id)
        {
            var mv = entity.mvc_test.Single(i => i.uid == id);
            mv.uid = p1.uid;
            mv.fname = p1.fname;
            mv.lname = p1.lname;
            mv.email = p1.email;
            entity.SaveChanges();
            return RedirectToAction("showEmp");
       
        }

        [HttpGet]
        public ActionResult Detail(int id)
        {
            var p1 = entity.mvc_test.Single(i => i.uid == id);
            Portal mv = new Portal();
            mv.uid = p1.uid;
            mv.fname = p1.fname;
            mv.lname = p1.lname;
            mv.email = p1.email;
            return View(mv);
        }

        [HttpGet]
        public ActionResult Delete(int id)
        {
            var p1 = entity.mvc_test.Single(i => i.uid == id);
            Portal mv = new Portal();
            mv.uid = p1.uid;
            mv.fname = p1.fname;
            mv.lname = p1.lname;
            mv.email = p1.email;
 
           return View(mv);

        }
        [HttpPost]
        public ActionResult Delete(Portal p,int id)
        {
            var p1 = entity.mvc_test.Single(i => i.uid == id);           
            entity.mvc_test.DeleteObject(p1);
            entity.SaveChanges();
            return RedirectToAction("showEmp");
        }
    }
read more

upload image in mvc

No comments
in controller


[HttpPost]
        public ActionResult Img(HttpPostedFileBase file)
        {
            if (!Directory.Exists(Server.MapPath("~/image")))
            {
                Directory.CreateDirectory(Server.MapPath("image"));
            }
            string name = file.FileName;
            string path = Path.Combine(Server.MapPath("~/image"),name);
            file.SaveAs(path);
            return RedirectToAction("Exp");
        }
read more

Thursday, 8 May 2014

online exam code behind

No comments
To check if radiobutton option selected or not and storing that value in database



   RadioButton rdo;
   string u_ans = "";
 public void store_choice()
    {
        try
        {
            Label llb = (Label)DetailsView1.FindControl("lblq");
            DetailsView f1 = (DetailsView)DetailsView1.FindControl("DetailsView2");
            if (((RadioButton)f1.FindControl("RadioButton1")).Checked == true)
            {
                rdo = (RadioButton)f1.FindControl("RadioButton1");
                u_ans = rdo.Text;
            }
            else if (((RadioButton)f1.FindControl("RadioButton2")).Checked == true)
            {
                rdo = (RadioButton)f1.FindControl("RadioButton2");
                u_ans = rdo.Text;
            }
            else if (((RadioButton)f1.FindControl("RadioButton3")).Checked == true)
            {
                rdo = (RadioButton)f1.FindControl("RadioButton3");
                u_ans = rdo.Text;
            }
            else if (((RadioButton)f1.FindControl("RadioButton4")).Checked == true)
            {
                rdo = (RadioButton)f1.FindControl("RadioButton4");
                u_ans = rdo.Text;
            }
            else
            {
                u_ans = "Not Attempt";
            }

            dl.question_no = Convert.ToInt16(llb.Text);
            dl.exam_id = Convert.ToInt16(lblid.Text);
            dl.stu_id = Convert.ToInt16(Session["Stu_id"]);
            dl.answer = u_ans;
            bl.stu_exams(dl);
        }
        catch (Exception)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(),
                     "ServerControlScript", "alert('Login First')", true);

        }

    }





keep radio button selected when page changes in detailsview


    protected void setQ()
    {
        Label llb = (Label)DetailsView1.FindControl("lblq");
        DetailsView f1 = (DetailsView)DetailsView1.FindControl("DetailsView2");
        RadioButton rd1 = (RadioButton)f1.FindControl("RadioButton1");
        RadioButton rd2 = (RadioButton)f1.FindControl("RadioButton2");
        RadioButton rd3 = (RadioButton)f1.FindControl("RadioButton3");
        RadioButton rd4 = (RadioButton)f1.FindControl("RadioButton4");
        dl.question_no = Convert.ToInt16(llb.Text);
        dl.stu_id = Convert.ToInt16(Session["Stu_id"]);
        string tmp = "";


        con.Open();
        cmd = new SqlCommand("user_ans", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@Question_no", dl.question_no);
        cmd.Parameters.AddWithValue("@Stu_id", dl.stu_id);
        SqlDataReader dr = cmd.ExecuteReader();
        // dr = bl.user_ans(dl);
        while (dr.Read())
        {
            tmp = dr[0].ToString();
        }
        dr.Close();
        if (tmp != "")
            ViewState["answer"] = tmp;

        if (rd1.Text == tmp)
        {
            rd1.Checked = true;
        }
        else if (rd2.Text == tmp)
        {
            rd2.Checked = true;
        }
        else if (rd3.Text == tmp)
        {
            rd3.Checked = true;
        }
        else if (rd4.Text == tmp)
        {
            rd4.Checked = true;
        }
        else { }
    }



bind detailsview within another detailsview


 public void bind_detailsview_within_detailsview()
    {
        for (int i = 0; i < DetailsView1.Rows.Count; i++)
        {
            Label l1 = (Label)DetailsView1.Rows[i].FindControl("lblq");
            DetailsView f1 = (DetailsView)DetailsView1.Rows[i].FindControl("DetailsView2");
            dl.question_no = Convert.ToInt16(l1.Text);
            f1.DataSource = bl.select_choice_stu(dl);
            f1.DataBind();
        }

    }



move to previous question in detailsview


    protected void btnprev_Click(object sender, EventArgs e)
    {
        store_choice();
        DetailsView1.PageIndex = DetailsView1.DataItemIndex - 1;
        ViewState["count"] = int.Parse(ViewState["count"].ToString()) - 1;
        bind_form();
        bind_form_choice();
        setQ();
    }


move to next question in detailsview
    protected void btnnext_Click(object sender, EventArgs e)
    {
        ViewState["count"] = int.Parse(ViewState["count"].ToString()) + 1;
        int itm = int.Parse(ViewState["count"].ToString());
        store_choice();
        bind_form();
        bind_form_choice();
        setQ();
        DetailsView1.PageIndex = DetailsView1.DataItemIndex + 1;
        //   Button btnNext = (Button)DetailsView1.FooterRow.FindControl("tnnext");
    }


ASPX to bind detailsview


<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
                        BorderStyle="Dashed" BorderWidth="2px" CellPadding="8" CellSpacing="8"
                        GridLines="None" Height="100%"
                        onpageindexchanging="DetailsView1_PageIndexChanging" style="margin-left:50px"
                        Width="70%">
                        <Fields>
                            <asp:BoundField DataField="Question_id" HeaderText="ID" Visible="False" />
                            <asp:TemplateField HeaderText="Question no">                              
                                <ItemTemplate>
                                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("Question_no") %>'
                                        Visible="False"></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField>                              
                                <ItemTemplate>
                                    <br />
                                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("Question_text") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField>                              
                                <ItemTemplate>
                                    <asp:DetailsView ID="DetailsView2" runat="server" AutoGenerateRows="False"
                                        GridLines="None" Height="100%" Width="100%">
                                        <Fields>
                                            <asp:TemplateField>                                              
                                                <ItemTemplate>
                                                    <br />
                                                    <asp:RadioButton ID="RadioButton1" runat="server"
                                                        GroupName='<%#Bind("Question_no") %>' Text='<%#Bind("Choice_1") %>' />
                                                    <asp:RadioButton ID="RadioButton2" runat="server" CssClass="qno"
                                                        GroupName='<%#Bind("Question_no") %>' Text='<%#Bind("Choice_2") %>' />
                                                    <br />
                                                    <br />
                                                    <br />
                                                    <asp:RadioButton ID="RadioButton3" runat="server"
                                                        GroupName='<%#Bind("Question_no") %>' Text='<%#Bind("Choice_3") %>' />
                                                    <asp:RadioButton ID="RadioButton4" runat="server" CssClass="qno"
                                                        GroupName='<%#Bind("Question_no") %>' Text='<%#Bind("Choice_4") %>' />
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                        </Fields>
                                    </asp:DetailsView>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField>                           
                                <HeaderTemplate>
                                    <br />
                                    <br />
                                    <br />
                                    <asp:Button ID="btnprev" runat="server" CssClass="padd" Height="28px"
                                        onclick="btnprev_Click" style="background-color:rgb(9, 16, 198);color:White"
                                        Text="Prev" Width="70px" />
                                </HeaderTemplate>                            
                                <ItemTemplate>
                                    <br />
                                    <br />
                                    <br />
                                    <asp:Button ID="tnnext" runat="server" CssClass="chkbtn" Height="28px"
                                        onclick="tnnext_Click" style="background-color:rgb(9, 16, 198);color:White"
                                        Text="Next" Width="70px" />
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Fields>
                    </asp:DetailsView> 
read more

calculate marks and select rows from storedprocedure

No comments
Query

select distinct Stu_exam.Stu_id,Stu_exam.Exam_id,Stu_exam.Question_no,Stu_exam.Answer,Questions.Answer_text from Stu_exam,Questions where Stu_exam.Stu_id=@Stu_id and Stu_exam.Exam_id=@Exam_id and Stu_exam.Question_no=Questions.Question_no and Stu_exam.Exam_id=Questions.Exam_id


.cs


protected void btnmarks_Click(object sender, EventArgs e)
    {
        store_choice();
        int Correct = 0, Incorrect = 0, Total = 0;
        dl.stu_id = Convert.ToInt16(Session["Stu_id"]);
        dl.exam_id = Convert.ToInt16(lblid.Text);
        DataTable dt = new DataTable();
        dt = bl.calculate_marks(dl);
        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i][3].ToString() == dt.Rows[i][4].ToString())
                {
                    Correct = Correct + 2;
                }
                else if (dt.Rows[i][3].ToString() != "Not Attempt")
                {
                    Incorrect = Incorrect + 0;
                }
            }
        }
        Total = Correct - Incorrect;
        dl.exam_name = lblname.Text;
        dl.exam_marks = Total;
        bl.insert_marks(dl);
        Response.Redirect("exam_marks.aspx");

    }
read more

Wednesday, 7 May 2014

SQL queries

No comments
 /* to select column for perticular months */

select tblcustomer.fname,tblcustomer.lname,tblProduct.pname,tblsale.sprice from tblcustomer inner join tblProduct on tblcustomer.cid=tblProduct.pid inner join tblsale on tblcustomer.cid=tblsale.sid where month(tblsale.date)=11

 /*  nested queries  */
select tblcustomer.fname,tblcustomer.lname,tblcustomer.cid from tblcustomer where not exists (select tblcustomer.fname,tblcustomer.lname,tblcustomer.cid from tblcustomer inner join tblsale on tblcustomer.cid=tblsale.sid)


select tblcustomer.fname,tblcustomer.lname,tblsale.sprice,tblProduct.rprice,abs(tblsale.sid-tblProduct.rprice) as [diff] from tblcustomer inner join tblsale on tblcustomer.cid=tblsale.sid inner join tblproduct on tblcustomer.cid=tblProduct.pid


 /*  find average */
select tblProduct.category,AVG(tblsale.sprice)as [average]from tblProduct inner join tblsale on tblProduct.pid=tblsale.sid  group by tblProduct.category




/*delete duplicate recordes */

        /* to see duplicate records */
            select col1,col2,count(*) as total from table group by col1,col2 having count(*)>1 order by total desc
       
        /* to delete duplicate record */
            with numbered as
            (select ROW_NUMBER() over(PARTITION BY col1,col2 order by col1,col2)as dup from table)
            delete from numbered where dup>1   
           
/* database attach detach */


/* detach */

use master;
go;
exec sp_detach_db @dbname=N'Buzzedu;

/* detach */


use master;
go
create database Buzzedu
on (filename ='C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\Buzzedu.mdf'),
(filename='C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\Buzzedu_log.ldf')
for attach;
go




/* create Check Constraints */

alter table job_applied add constraint chk_job_applied check(Stu_id>0)

/* drop Constraints */

alter table job_applied drop constraint chk_job_applied


/* to update row */

update Job_applied set Stu_id=REPLACE(Stu_id,0,1)



/*delete child when delete parent/*



alter table Stu_reply add constraint FK_Stu_thread_Thread_id foreign key(Thread_id) references Stu_thread(Thread_id) on delete cascade

alter table Groups_join add constraint FK_Groups_Group_id foreign key(Group_id) references Groups(Group_id) on delete cascade

alter table Stu_thread add constraint FK_Groups_Group foreign key(Group_id) references Groups(Group_id) on delete cascade


/*unique index */


CREATE UNIQUE INDEX UX01_YourTable ON dbo.YourTable(SomeUniqueColumn)

ALTER TABLE dbo.YourChildTable
   ADD CONSTRAINT FK_ChildTable_Table
   FOREIGN KEY(YourFKColumn) REFERENCES dbo.YourTable(SomeUniqueColumn)



/********trigger*************/


Create table tblCustomer(uid int primary key,name varchar(200),balance int);

Create table tblStatement (sid int,userid int references tblCustomer(uid),deposit int);


select * from tblCustomer
select * from tblStatement


CREATE TRIGGER triggerte1 on
tblStatement
after insert
as
begin
declare @uid int,@dp int
select @uid=userid,@dp=deposit from inserted
update tblCustomer set balance=balance+@dp where uid=@uid
end

insert into tblCustomer(uid,name,balance) values (1,'vikas',200)
insert into tblStatement(sid,userid,deposit) values (1,1,700)


Full outer join

select * from Stu_thread full outer join Groups_join on Stu_thread.Group_name=Groups_join.Group_name where Stu_thread.Group_name=@Group_name
read more

Sunday, 4 May 2014

Update datatable with gridview

No comments
 protected void btnupdate_Click(object sender, EventArgs e)
    {       
        Button bt1 = (Button)sender;
        GridViewRow gr1 = (GridViewRow)bt1.NamingContainer;
        DataTable dt1 = (DataTable)Session["data"];
        DataRow dr = dt1.Rows[gr1.RowIndex];

        Label productid = (Label)GridView1.Rows[gr1.RowIndex].FindControl("lblpid");
        Image img = (Image)GridView1.Rows[gr1.RowIndex].FindControl("Image1");
        Label pid = (Label)GridView1.Rows[gr1.RowIndex].FindControl("lblproduct_id");       
        if (tx.Text == "")
        {
            lblnoqty.Visible = true;
        }
        else
        {          
            dr["p_id"] = productid.Text;
            dr["Product_id"] = pid.Text;
            dr["Product_name"] = pname.Text;          
            GridView1.DataSource = dt1;          
            GridView1.DataBind();         
        }
read more

To create random number and adding rows from one table to another

No comments
  protected void btn_checkout_Click(object sender, EventArgs e)
    {
        string chars="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random=new Random();
        string result=new string(Enumerable.Repeat(chars,10).Select(s=>s[random.Next(s.Length)]).ToArray());
        Session["corder"] = result;
        DateTime time = DateTime.Now.Date;
        DataTable dt = (DataTable)Session["cart"];

        Label username = new Label();
        Label email = new Label();
        Label address = new Label();
        Label country = new Label();
        Label state = new Label();
        Label city = new Label();
        Label pincode = new Label();

        for (int j = 0; j < dt.Rows.Count; j++)
        {
            dl.username = Session["usename"].ToString();           
            DataSet ds = new DataSet();
            ds = bl.select_user(dl);

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                username.Text = row[1].ToString();
                email.Text = row[2].ToString();
                address.Text = row[5].ToString();
                country.Text = row[6].ToString();
                state.Text = row[7].ToString();
                city.Text = row[8].ToString();
                pincode.Text = row[9].ToString();
            }
            dl.order_code =result;
            dl.order_date = time;
            dl.p_id = Convert.ToInt16(dt.Rows[j]["p_id"]);
            dl.products_id = Convert.ToInt16(dt.Rows[j]["Product_id"]);
            dl.category = dt.Rows[j]["Category"].ToString();
            dl.product_name = dt.Rows[j]["Product_name"].ToString();
            dl.price = Convert.ToInt16(dt.Rows[j]["Price"]);
            dl.qty = Convert.ToInt16(dt.Rows[j]["qty"]);
            dl.tprice = Convert.ToInt16(dt.Rows[j]["tprice"]);
            dl.payable_amount = Convert.ToInt16(lbltotal.Text);
            dl.username = username.Text;
            dl.email = email.Text;
            dl.address = address.Text;
            dl.country = country.Text;
            dl.state = state.Text;
            dl.city = city.Text;
            dl.pincode = Convert.ToInt32(pincode.Text);
            bl.insert_order(dl);                                             
        }
read more

Repeater Example-nested repeater

No comments

            <asp:Repeater ID="repeaterthread" runat="server">
                <HeaderTemplate>
                    <table style="border-bottom:1px solid #C9C9F3;width:100%;border-left:1px solid #C9C9F3">
                        <tr style="background-color:Blue;color:White;height:45px">
                            <td colspan="2">
                                <b style="margin-left:10px">Messages Of Your Current Group</b>
                            </td>
                        </tr>
                    </table>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr>
                        <td>
                            <table style="border-bottom:1px solid #C9C9F3;width:100%;border-left:1px solid #C9C9F3">
                                <tr style="background-color:rgb(35, 143, 195);color:White;height:15px">
                                    <td colspan="2">
                                        <b style="margin-left:10px">Message</b>
                                        <asp:LinkButton ID="linkdelete" runat="server"
                                            CommandArgument='<%#Eval("Thread_id") %>' OnClick="linkdeletepost"
                                            OnClientClick="return del()"
                                            style="float:right;height:10px;text-decoration:none;color:Red">Delete</asp:LinkButton>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <tr>
                                <td>
                                    <br />
                                    <table style="width:100%">
                                        <tr>
                                            <td>
                                                <asp:Label ID="lblth" runat="server" Text='<%#Bind("Thread_id") %>'
                                                    Visible="false"></asp:Label>
                                                <asp:Label ID="lblmessage" runat="server" Text='<%#Eval("Thread_message") %>'
                                                    Visible="true"></asp:Label>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <br />
                            <table style="background-color:#EBEFF0;border-bottom:1px dotted Black;width:100%">
                                <tr>
                                    <td>
                                        <asp:Label ID="lbldate" runat="server" Font-Bold="true"
                                            style="font-size:smaller" Text='<%#Eval("Thread_date") %>'></asp:Label>
                                        <asp:LinkButton ID="linkbuttonreply" runat="server"
                                            CommandArgument='<%#Eval("Thread_id") %>' CommandName="reply"
                                            OnClick="reply_click"
                                            style="float:right;margin-right:30px;text-decoration:none;font-size:large">Reply</asp:LinkButton>
                                        <br />
                                        <br />
                                    </td>
                                </tr>
                            </table>
                            <br />
                            <tr>
                                <td>
                                    <asp:Repeater ID="repeaterreply" runat="server">
                                        <HeaderTemplate>
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <table style="border-bottom:1px solid #C9C9F3;width:100%;border-left:1px solid #C9C9F3">
                                                <tr style="background-color:#009933;color:White;height:20px">
                                                    <td colspan="2">
                                                        <b style="margin-left:10px">Reply</b>
                                                        <asp:LinkButton ID="linkdeletereply" runat="server"
                                                            CommandArgument='<%#Eval("Reply_id") %>' OnClick="linkdeletereply"
                                                            OnClientClick="return del()"
                                                            style="float:right;height:10px;text-decoration:none;color:Red">Delete</asp:LinkButton>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <table style="background-color:#EBEFF0;border-left:1px dotted #009933;border-right:1px dotted #009933;border-bottom:1px solid #009933; width:100%">
                                                            <tr>
                                                                <td>
                                                                    <asp:Label ID="lblreplypost" runat="server" Text='<%#Eval("Reply_message") %>'></asp:Label>
                                                                    <br />
                                                                    <br />
                                                                    <asp:Label ID="Label1" runat="server" style="font-size:smaller"
                                                                        Text='<%#Eval("Reply_time") %>'></asp:Label>
                                                                    <asp:Label ID="Label3" runat="server" style="margin-left:770px" Text="From : "></asp:Label>
                                                                    <asp:Label ID="Label2" runat="server"
                                                                        style="font-size:Medium;font-weight:bold;float:right;margin-right:20px"
                                                                        Text='<%#Eval("Fullname") %>'></asp:Label>
                                                                    <br />
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </td>
                                                </tr>
                                            </table>
                                        </ItemTemplate>
                                        <FooterTemplate>
                                            </table>
                                        </FooterTemplate>
                                    </asp:Repeater>
                                </td>
                            </tr>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <table style="width:100%;background-color:Silver">
                                <tr>
                                    <td>
                                        <asp:TextBox ID="txtreply" runat="server" AutoPostBack="True"
                                            style="width:900px;height:30px;margin-left:30px;margin-top:10px"
                                            Visible="false">
                         </asp:TextBox>
                                        <br />
                                        <asp:Button ID="btnpostreply" runat="server"
                                            CommandArgument='<%#Eval("Thread_id") %>' Height="28px" OnClick="post_reply" style="float:right;margin-right:10px;margin-top:5px;
                           background-color:rgb(91, 116, 168);margin-right:70px" Text="Post" Visible="false"
                                            Width="70px" />
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </ItemTemplate>
                <FooterTemplate>
                    </table>
                </FooterTemplate>
            </asp:Repeater>


binding nested repeater

    public void repeater_reply_bind()
    {
        for(int i=0;i<repeaterthread.Items.Count;i++)
        {
          Label l1 = (Label)repeaterthread.Items[i].FindControl("lblth");
           Repeater r1 = (Repeater)repeaterthread.Items[i].FindControl("repeaterreply");
           dl.Thread_id = Convert.ToInt16(l1.Text);
            r1.DataSource = bl.show_reply_message(dl);
            r1.DataBind();
        }
    }

to find item from repeater

 protected void reply_click(object sender, EventArgs e)
    {
     
            LinkButton l1 = (LinkButton)sender;
            RepeaterItem r1 = (RepeaterItem)l1.NamingContainer;
            TextBox t1 = (TextBox)repeaterthread.Items[r1.ItemIndex].FindControl("txtreply");
            Button b1 = (Button)repeaterthread.Items[r1.ItemIndex].FindControl("btnpostreply");
            t1.Visible = true;
            b1.Visible = true;       
    }



read more