Wednesday, November 17, 2010

Creating control at runtime in C#Codebehind

 private DataSet GetTemplatesDs()
            string sqlToExecute = "select TemplateName,Subject  from Template";
            SqlDataAdapter da = new SqlDataAdapter(sqlToExecute, con);
            DataSet ds = new DataSet();
            da.Fill(ds, "Distribution_Mail_Template");
            Session["TemplatesDs"] = ds;
            return ds;

private void PopulateUI()//user defined function
                  Label[] additionalApplicants;
                  DataSet gettemplatesDs = GetTemplatesDs()
                        if (gettemplatesDs .Tables.Count > 0 && gettemplatesDs .Tables.Count > 0)
                            for (int i = 0; i < gettemplatesDs .Tables[0].Rows.Count; i++)
                                additionalApplicants = new Label[gettemplatesDs .Tables[0].Rows.Count];
                                additionalApplicants[i] = new Label();
                                additionalApplicants[i].ID = gettemplatesDs .Tables[0].Rows[0][""].ToString();
                                additionalApplicants[i].Text =gettemplatesDs .Tables[0].Rows[0][""].ToString();
                               this.Page.Controls.Add(additionalApplicants); //Adding controls to webpage

1 comment:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru ASP.NET Essential Training Online . Nowadays Dot Net has tons of job opportunities on various vertical industry.
    or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.