This is one sample from my fresher time coding
Explain:
In my sample code was dynamic generate textboxes and lables with empty validations(required field validator).The textbox's and lable's created by my database query return count and values.
DataView dvFamily = new DataView();
dvFamily = o_LoginUser.GetFamily(ParentId);//DataBase call
DataView dvUser = new DataView();
dvUser = o_LoginUser.GetAdult(CurrentUserId);//DataBase call
then. we want how many textbox's from database count?? and bind textboxes,lables?
public void BindFamily()
{
DataView dvFamily = new DataView();
dvFamily = o_LoginUser.GetFamily(ParentId);//DB call
DataView dvUser = new DataView();
dvUser = o_LoginUser.GetAdult(CurrentUserId);
if (dvFamily.Table.Rows.Count != 0 && dvUser.Table.Rows.Count != 0)//Check count
{
for (int j = 0; j < dvFamily.Table.Rows.Count; j++)
{
int i = j + 1;
Label lbHeader = new Label();//New lable
lbHeader.ID = "lbHeader" + j;//Set Id for the lable
string sb = o_LoginUser.NumberToText(i);
lbHeader.Text = "Children Detail" + sb.ToString().TrimEnd();//lable Text
lbHeader.SkinID = "lblHeaderStyle";//Style from skin
pnlChildDetail.Controls.Add(lbHeader);//Add the lable to one panel control.
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));//Apply style
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));
//Create Dynamic textboxes with required field validator .
TextBox tbChildFirstName = new TextBox();
Label lblChildFirstName = new Label();
lblChildFirstName.ID = "lblChildFirstName" + j;
lblChildFirstName.Text = "Children FirstName";
lblChildFirstName.Width = 200;
lblChildFirstName.SkinID = "Outlabel";
tbChildFirstName.ID = "txtChildFirstName" + j;
tbChildFirstName.Text = dvFamily[j]["FIRST_NAME"].ToString();
pnlChildDetail.Controls.Add(lblChildFirstName);
pnlChildDetail.Controls.Add(tbChildFirstName);
RequiredFieldValidator rqf = new RequiredFieldValidator();
rqf.ID = "rqf" + i;
pnlChildDetail.Controls.Add(rqf);
rqf.ControlToValidate = "txtChildFirstName" + j;
rqf.ErrorMessage = "Children FirstName is required";
rqf.Display = ValidatorDisplay.Dynamic;
rqf.ValidationGroup = "EligibilityCheck";
rqf.SetFocusOnError = true;
rqf.Text = "*";
tbChildFirstName.Attributes.Add("runat", "server");
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));
TextBox tbChildMiddleName = new TextBox();
Label lblChildMiddleName = new Label();
lblChildMiddleName.ID = "lblChildMiddleName" + j;
lblChildMiddleName.Text = "Children MiddleName";
lblChildMiddleName.Width = 200;
tbChildMiddleName.ID = "txtChildMiddleName" + j;
tbChildMiddleName.Text = dvFamily[j]["MIDDLE_NAME"].ToString();
lblChildMiddleName.SkinID = "Outlabel";
pnlChildDetail.Controls.Add(lblChildMiddleName);
pnlChildDetail.Controls.Add(tbChildMiddleName);
RequiredFieldValidator rqf1 = new RequiredFieldValidator();
rqf1.ID = "rqf1" + i;
pnlChildDetail.Controls.Add(rqf1);
rqf1.ControlToValidate = "txtChildMiddleName" + j;
rqf1.ErrorMessage = "Children MiddleName is required";
rqf1.Display = ValidatorDisplay.Dynamic;
rqf1.ValidationGroup = "EligibilityCheck";
rqf1.Text = "*";
rqf1.SetFocusOnError = true;
tbChildMiddleName.Attributes.Add("runat", "server");
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));
TextBox tbChildrenLastName = new TextBox();
Label lblChildrenLastName = new Label();
lblChildrenLastName.ID = "lblChildrenLastName" + j;
lblChildrenLastName.Text = "Children LastName";
lblChildrenLastName.Width = 200;
tbChildrenLastName.ID = "txtChildrenLastName" + j;
tbChildrenLastName.Text = dvFamily[j]["LAST_NAME"].ToString();
lblChildrenLastName.SkinID = "Outlabel";
pnlChildDetail.Controls.Add(lblChildrenLastName);
pnlChildDetail.Controls.Add(tbChildrenLastName);
RequiredFieldValidator rqf2 = new RequiredFieldValidator();
rqf2.ID = "rqf2" + i;
pnlChildDetail.Controls.Add(rqf2);
rqf2.ControlToValidate = "txtChildrenLastName" + j;
rqf2.ErrorMessage = "Children LastName is required";
rqf2.Display = ValidatorDisplay.Dynamic;
rqf2.ValidationGroup = "EligibilityCheck";
rqf2.Text = "*";
rqf2.SetFocusOnError = true;
tbChildrenLastName.Attributes.Add("runat", "server");
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));
TextBox tbChildrenDOB = new TextBox();
Label lblChildrenDOB = new Label();
lblChildrenDOB.ID = "lblChildrenDOB" + j;
lblChildrenDOB.Text = "Children DOB";
tbChildrenDOB.ID = "txtChildrenDOB" + j;
lblChildrenDOB.Width = 200;
tbChildrenDOB.Text = dvFamily[j]["DOB"].ToString();
lblChildrenDOB.SkinID = "Outlabel";
pnlChildDetail.Controls.Add(lblChildrenDOB);
pnlChildDetail.Controls.Add(tbChildrenDOB);
RequiredFieldValidator rqf3 = new RequiredFieldValidator();
rqf3.ID = "rqf3" + i;
pnlChildDetail.Controls.Add(rqf3);
rqf3.ControlToValidate = "txtChildrenDOB" + j;
rqf3.ErrorMessage = "Children DOB is required";
rqf3.Display = ValidatorDisplay.Dynamic;
rqf3.ValidationGroup = "EligibilityCheck";
rqf3.Text = "*";
rqf3.SetFocusOnError = true;
tbChildrenDOB.Attributes.Add("runat", "server");
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));
DropDownList ddlChildrenGender = new DropDownList();
Label lblChildreGender = new Label();
lblChildreGender.ID = "lblGender" + j;
lblChildreGender.Text = "Children Gender";
ddlChildrenGender.ID = "ddlChildrenGender" + j;
lblChildreGender.Width = 200;
ddlChildrenGender.Width = 155;
ddlChildrenGender.Items.Add(new ListItem("M", "M"));
ddlChildrenGender.Items.Add(new ListItem("F", "F"));
ddlChildrenGender.Attributes.Add("runat", "server");
ddlChildrenGender.SelectedValue = dvFamily[j]["GENDER"].ToString();
ddlChildrenGender.SkinID = "ddlStyle";
lblChildreGender.SkinID = "Outlabel";
pnlChildDetail.Controls.Add(lblChildreGender);
pnlChildDetail.Controls.Add(ddlChildrenGender);
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));
TextBox tbSchoolName = new TextBox();
Label lblSchoolName = new Label();
lblSchoolName.ID = "lblSchoolName" + j;
lblSchoolName.Text = "Children SchoolName";
tbSchoolName.ID = "txtSchoolName" + j;
lblSchoolName.Width = 200;
tbSchoolName.Attributes.Add("runat", "server");
tbSchoolName.Text = dvFamily[j]["SCHOOL_NAME"].ToString();
lblSchoolName.SkinID = "Outlabel";
pnlChildDetail.Controls.Add(lblSchoolName);
pnlChildDetail.Controls.Add(tbSchoolName);
RequiredFieldValidator rqf4 = new RequiredFieldValidator();
rqf4.ID = "rqf4" + i;
pnlChildDetail.Controls.Add(rqf4);
rqf4.ControlToValidate = "txtSchoolName" + j;
rqf4.ErrorMessage = "Children SchoolName is required";
rqf4.Display = ValidatorDisplay.Dynamic;
rqf4.ValidationGroup = "EligibilityCheck";
rqf4.Text = "*";
rqf4.SetFocusOnError = true;
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));
pnlChildDetail.Controls.Add(GetLiteral("................................................................................................................................................................................................................."));
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));
}
}
}
//add style for try it
public Literal GetLiteral(string text)
{
Literal rv = default(Literal);
rv = new Literal();
rv.Text = text;
return rv;
}
Aspx
panel:
<asp:Panel ID="pnlChildDetail" Style="text-align: left; padding-left: 10px" Width="100%"
runat="server">
</asp:Panel>
ok now finished the task.but then how to get textbox values from panel???
use this line
TextBox objTextBox3 = (TextBox)pnlChildDetail.FindControl("strtxtChildrenDOB");
But you watch my below sample .because its explain some more details
protected void btnUpdate_Click(object sender, EventArgs e)
{
DataView dvGetTribalAdminMailId = new DataView();
dvGetTribalAdminMailId = o_LoginUser.GetTribalAdminMailId();
//string ToEmail = "goldramesh.cool@gmail.com";
if (dvGetTribalAdminMailId.Table.Rows.Count != 0)
{
for (int k = 0; k < dvGetTribalAdminMailId.Table.Rows.Count; k++)
{
DataView dvFamily = new DataView();
dvFamily = o_LoginUser.GetFamily(ParentId);
DataView dvUser = new DataView();
dvUser = o_LoginUser.GetAdult(CurrentUserId);
if (dvFamily.Table.Rows.Count != 0 && dvUser.Table.Rows.Count != 0)
{
int PARENT_ID = Convert.ToInt32(dvFamily[0]["PARENT_ID"].ToString());
string ParentFirstName = dvFamily[0]["PARENT_FIRST_NAME"].ToString();
string PARENT_LAST_NAME = dvFamily[0]["PARENT_LAST_NAME"].ToString();
string PARENT_PHONE_NUMBER = dvUser[0]["CELL_NUMBER"].ToString();
string PARENT_NASS_REF = dvFamily[0]["PARENT_NASS_REF"].ToString();
string PARENT_NI_NUMBER = dvFamily[0]["PARENT_NI_NUMBER"].ToString();
string PARENT_GENDER = dvFamily[0]["PARENT_GENDER"].ToString();
Authentication objAuthentication = new Authentication();
DateTime AddedDate = System.DateTime.Now;
DataView dvNINASSNumber = new DataView();
string UserName = HttpContext.Current.User.Identity.Name.Split('|')[0];
StringBuilder sbSubject = new StringBuilder();
StringBuilder sbBody = new StringBuilder();
sbSubject.Append("Profile Update");
sbBody.Append("<div> Dear Admin,</div>");
sbBody.Append("<br/>");
sbBody.Append("<div> The user" +" "+ ParentFirstName + " has updated the following details.</div>");
sbBody.Append("<br/>");
sbBody.Append(lblParentdetail.Text);
sbBody.Append("<br/>");
sbBody.Append("<br/>");
sbBody.Append("Previous ParentFirstName =");
sbBody.Append(ParentFirstName);
sbBody.Append("<br/>");
sbBody.Append("New ParentFirstName =");
sbBody.Append(txtFirstName.Text);
sbBody.Append("<br/>");
sbBody.Append("Previous ParentLastName =");
sbBody.Append(PARENT_LAST_NAME);
sbBody.Append("<br/>");
sbBody.Append("New ParentLastName =");
sbBody.Append(txtLastName.Text);
sbBody.Append("<br/>");
sbBody.Append("Previous ParentPhoneNumber =");
sbBody.Append(PARENT_PHONE_NUMBER);
sbBody.Append("<br/>");
sbBody.Append("New ParentPhoneNumber =");
sbBody.Append(txtPhoneNumber.Text);
sbBody.Append("<br/>");
sbBody.Append("Previous ParentNASSREFF =");
sbBody.Append(PARENT_NASS_REF);
sbBody.Append("<br/>");
sbBody.Append("New ParentNASSREFF=");
sbBody.Append(txtNASSReference.Text);
sbBody.Append("<br/>");
sbBody.Append("Previous Parent NI Number =");
sbBody.Append(PARENT_NI_NUMBER);
sbBody.Append("<br/>");
sbBody.Append("New Parent NI Number =");
sbBody.Append(txtNINumber.Text);
sbBody.Append("<br/>");
sbBody.Append("Previous Parent Gender =");
sbBody.Append(PARENT_GENDER);
sbBody.Append("<br/>");
sbBody.Append("New Parent Gender =");
sbBody.Append(ddlGender.SelectedValue);
sbBody.Append("<br/>");
for (int i = 0; i < dvFamily.Table.Rows.Count; i++)
{
sbBody.Append("<br/>");
sbBody.Append("<br/>");
int j = i + 1;
Label lbHeader = new Label();
lbHeader.ID = "lbHeader" + i;
string sb = o_LoginUser.NumberToText(j);
lbHeader.Text = "Children Detail" + sb.ToString().TrimEnd();
lbHeader.Width = 200;
sbBody.Append(lbHeader.Text);
sbBody.Append("<br/>");
sbBody.Append("<br/>");
string ChildFirstName = dvFamily[i]["FIRST_NAME"].ToString();
string ChildMiddleName = dvFamily[i]["MIDDLE_NAME"].ToString();
string ChildrenLastName = dvFamily[i]["LAST_NAME"].ToString();
string ChildrenDOB = dvFamily[i]["DOB"].ToString();
string SchoolName = dvFamily[i]["SCHOOL_NAME"].ToString();
string ChildrenGender = dvFamily[i]["GENDER"].ToString();
sbBody.Append("Previous Children FirstName =");
sbBody.Append(ChildFirstName);
sbBody.Append("<br/>");
sbBody.Append("New Children FirstName =");
string strControlName = "txtChildFirstName" + i;
TextBox objTextBox = (TextBox)pnlChildDetail.FindControl(strControlName);
string str = objTextBox.Text;
sbBody.Append(str);
sbBody.Append("<br/>");
sbBody.Append("Previous Children MiddleName =");
sbBody.Append(ChildMiddleName);
sbBody.Append("<br/>");
sbBody.Append("New Children MiddleName =");
string strtxtChildMiddleName = "txtChildMiddleName" + i;
TextBox objTextBox1 = (TextBox)pnlChildDetail.FindControl(strtxtChildMiddleName);
string str1 = objTextBox1.Text;
sbBody.Append(str1);
sbBody.Append("<br/>");
sbBody.Append("Previous Children LastName =");
sbBody.Append(ChildrenLastName);
sbBody.Append("<br/>");
sbBody.Append("New Children LastName=");
string strtxtChildrenLastName = "txtChildrenLastName" + i;
TextBox objTextBox2 = (TextBox)pnlChildDetail.FindControl(strtxtChildrenLastName);
string strChildrenLastName = objTextBox2.Text;
sbBody.Append(strChildrenLastName);
sbBody.Append("<br/>");
sbBody.Append("Previous Children DOB =");
sbBody.Append(ChildrenDOB);
sbBody.Append("<br/>");
sbBody.Append("New Children DOB =");
string strtxtChildrenDOB = "txtChildrenDOB" + i;
TextBox objTextBox3 = (TextBox)pnlChildDetail.FindControl(strtxtChildrenDOB);
string strChildrenDOB = objTextBox3.Text;
sbBody.Append(strChildrenDOB);
sbBody.Append("<br/>");
sbBody.Append("Previous Children SchoolName =");
sbBody.Append(SchoolName);
sbBody.Append("<br/>");
sbBody.Append("New Children SchoolName =");
string strtxtSchoolName = "txtSchoolName" + i;
TextBox objTextBox4 = (TextBox)pnlChildDetail.FindControl(strtxtSchoolName);
string strSchoolName = objTextBox4.Text;
sbBody.Append(strSchoolName);
sbBody.Append("<br/>");
sbBody.Append("Previous Children Gender =");
sbBody.Append(ChildrenGender);
sbBody.Append("<br/>");
sbBody.Append("New Children Gender =");
string strddlChildrenGender = "ddlChildrenGender" + i;
DropDownList objTextBox5 = (DropDownList)pnlChildDetail.FindControl(strddlChildrenGender);
string strChildrenGender = objTextBox5.Text;
sbBody.Append(strChildrenGender);
sbBody.Append("<br/>");
}
sbBody.Append("<br/> .........<br/>");
sbBody.Append(" <div> Thanks, </div>");
sbBody.Append(" <div> Solihull Metropolitan Borough Council</div>");
string ToEmail = dvGetTribalAdminMailId[k]["EmailId"].ToString();
o_EmailManager.SendMail(UserName, ToEmail, sbSubject.ToString(), sbBody.ToString());
tblError.Visible = true;
lblSuccessMessage.Visible = true;
lblSuccessMessage.ForeColor = System.Drawing.Color.Green;
}
}
}
}
Good luck.Happy coding.....
Explain:
In my sample code was dynamic generate textboxes and lables with empty validations(required field validator).The textbox's and lable's created by my database query return count and values.
DataView dvFamily = new DataView();
dvFamily = o_LoginUser.GetFamily(ParentId);//DataBase call
DataView dvUser = new DataView();
dvUser = o_LoginUser.GetAdult(CurrentUserId);//DataBase call
then. we want how many textbox's from database count?? and bind textboxes,lables?
public void BindFamily()
{
DataView dvFamily = new DataView();
dvFamily = o_LoginUser.GetFamily(ParentId);//DB call
DataView dvUser = new DataView();
dvUser = o_LoginUser.GetAdult(CurrentUserId);
if (dvFamily.Table.Rows.Count != 0 && dvUser.Table.Rows.Count != 0)//Check count
{
for (int j = 0; j < dvFamily.Table.Rows.Count; j++)
{
int i = j + 1;
Label lbHeader = new Label();//New lable
lbHeader.ID = "lbHeader" + j;//Set Id for the lable
string sb = o_LoginUser.NumberToText(i);
lbHeader.Text = "Children Detail" + sb.ToString().TrimEnd();//lable Text
lbHeader.SkinID = "lblHeaderStyle";//Style from skin
pnlChildDetail.Controls.Add(lbHeader);//Add the lable to one panel control.
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));//Apply style
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));
//Create Dynamic textboxes with required field validator .
TextBox tbChildFirstName = new TextBox();
Label lblChildFirstName = new Label();
lblChildFirstName.ID = "lblChildFirstName" + j;
lblChildFirstName.Text = "Children FirstName";
lblChildFirstName.Width = 200;
lblChildFirstName.SkinID = "Outlabel";
tbChildFirstName.ID = "txtChildFirstName" + j;
tbChildFirstName.Text = dvFamily[j]["FIRST_NAME"].ToString();
pnlChildDetail.Controls.Add(lblChildFirstName);
pnlChildDetail.Controls.Add(tbChildFirstName);
RequiredFieldValidator rqf = new RequiredFieldValidator();
rqf.ID = "rqf" + i;
pnlChildDetail.Controls.Add(rqf);
rqf.ControlToValidate = "txtChildFirstName" + j;
rqf.ErrorMessage = "Children FirstName is required";
rqf.Display = ValidatorDisplay.Dynamic;
rqf.ValidationGroup = "EligibilityCheck";
rqf.SetFocusOnError = true;
rqf.Text = "*";
tbChildFirstName.Attributes.Add("runat", "server");
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));
TextBox tbChildMiddleName = new TextBox();
Label lblChildMiddleName = new Label();
lblChildMiddleName.ID = "lblChildMiddleName" + j;
lblChildMiddleName.Text = "Children MiddleName";
lblChildMiddleName.Width = 200;
tbChildMiddleName.ID = "txtChildMiddleName" + j;
tbChildMiddleName.Text = dvFamily[j]["MIDDLE_NAME"].ToString();
lblChildMiddleName.SkinID = "Outlabel";
pnlChildDetail.Controls.Add(lblChildMiddleName);
pnlChildDetail.Controls.Add(tbChildMiddleName);
RequiredFieldValidator rqf1 = new RequiredFieldValidator();
rqf1.ID = "rqf1" + i;
pnlChildDetail.Controls.Add(rqf1);
rqf1.ControlToValidate = "txtChildMiddleName" + j;
rqf1.ErrorMessage = "Children MiddleName is required";
rqf1.Display = ValidatorDisplay.Dynamic;
rqf1.ValidationGroup = "EligibilityCheck";
rqf1.Text = "*";
rqf1.SetFocusOnError = true;
tbChildMiddleName.Attributes.Add("runat", "server");
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));
TextBox tbChildrenLastName = new TextBox();
Label lblChildrenLastName = new Label();
lblChildrenLastName.ID = "lblChildrenLastName" + j;
lblChildrenLastName.Text = "Children LastName";
lblChildrenLastName.Width = 200;
tbChildrenLastName.ID = "txtChildrenLastName" + j;
tbChildrenLastName.Text = dvFamily[j]["LAST_NAME"].ToString();
lblChildrenLastName.SkinID = "Outlabel";
pnlChildDetail.Controls.Add(lblChildrenLastName);
pnlChildDetail.Controls.Add(tbChildrenLastName);
RequiredFieldValidator rqf2 = new RequiredFieldValidator();
rqf2.ID = "rqf2" + i;
pnlChildDetail.Controls.Add(rqf2);
rqf2.ControlToValidate = "txtChildrenLastName" + j;
rqf2.ErrorMessage = "Children LastName is required";
rqf2.Display = ValidatorDisplay.Dynamic;
rqf2.ValidationGroup = "EligibilityCheck";
rqf2.Text = "*";
rqf2.SetFocusOnError = true;
tbChildrenLastName.Attributes.Add("runat", "server");
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));
TextBox tbChildrenDOB = new TextBox();
Label lblChildrenDOB = new Label();
lblChildrenDOB.ID = "lblChildrenDOB" + j;
lblChildrenDOB.Text = "Children DOB";
tbChildrenDOB.ID = "txtChildrenDOB" + j;
lblChildrenDOB.Width = 200;
tbChildrenDOB.Text = dvFamily[j]["DOB"].ToString();
lblChildrenDOB.SkinID = "Outlabel";
pnlChildDetail.Controls.Add(lblChildrenDOB);
pnlChildDetail.Controls.Add(tbChildrenDOB);
RequiredFieldValidator rqf3 = new RequiredFieldValidator();
rqf3.ID = "rqf3" + i;
pnlChildDetail.Controls.Add(rqf3);
rqf3.ControlToValidate = "txtChildrenDOB" + j;
rqf3.ErrorMessage = "Children DOB is required";
rqf3.Display = ValidatorDisplay.Dynamic;
rqf3.ValidationGroup = "EligibilityCheck";
rqf3.Text = "*";
rqf3.SetFocusOnError = true;
tbChildrenDOB.Attributes.Add("runat", "server");
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));
DropDownList ddlChildrenGender = new DropDownList();
Label lblChildreGender = new Label();
lblChildreGender.ID = "lblGender" + j;
lblChildreGender.Text = "Children Gender";
ddlChildrenGender.ID = "ddlChildrenGender" + j;
lblChildreGender.Width = 200;
ddlChildrenGender.Width = 155;
ddlChildrenGender.Items.Add(new ListItem("M", "M"));
ddlChildrenGender.Items.Add(new ListItem("F", "F"));
ddlChildrenGender.Attributes.Add("runat", "server");
ddlChildrenGender.SelectedValue = dvFamily[j]["GENDER"].ToString();
ddlChildrenGender.SkinID = "ddlStyle";
lblChildreGender.SkinID = "Outlabel";
pnlChildDetail.Controls.Add(lblChildreGender);
pnlChildDetail.Controls.Add(ddlChildrenGender);
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));
TextBox tbSchoolName = new TextBox();
Label lblSchoolName = new Label();
lblSchoolName.ID = "lblSchoolName" + j;
lblSchoolName.Text = "Children SchoolName";
tbSchoolName.ID = "txtSchoolName" + j;
lblSchoolName.Width = 200;
tbSchoolName.Attributes.Add("runat", "server");
tbSchoolName.Text = dvFamily[j]["SCHOOL_NAME"].ToString();
lblSchoolName.SkinID = "Outlabel";
pnlChildDetail.Controls.Add(lblSchoolName);
pnlChildDetail.Controls.Add(tbSchoolName);
RequiredFieldValidator rqf4 = new RequiredFieldValidator();
rqf4.ID = "rqf4" + i;
pnlChildDetail.Controls.Add(rqf4);
rqf4.ControlToValidate = "txtSchoolName" + j;
rqf4.ErrorMessage = "Children SchoolName is required";
rqf4.Display = ValidatorDisplay.Dynamic;
rqf4.ValidationGroup = "EligibilityCheck";
rqf4.Text = "*";
rqf4.SetFocusOnError = true;
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));
pnlChildDetail.Controls.Add(GetLiteral("................................................................................................................................................................................................................."));
pnlChildDetail.Controls.Add(GetLiteral("<br/>"));
}
}
}
//add style for try it
public Literal GetLiteral(string text)
{
Literal rv = default(Literal);
rv = new Literal();
rv.Text = text;
return rv;
}
Aspx
panel:
<asp:Panel ID="pnlChildDetail" Style="text-align: left; padding-left: 10px" Width="100%"
runat="server">
</asp:Panel>
ok now finished the task.but then how to get textbox values from panel???
use this line
TextBox objTextBox3 = (TextBox)pnlChildDetail.FindControl("strtxtChildrenDOB");
But you watch my below sample .because its explain some more details
protected void btnUpdate_Click(object sender, EventArgs e)
{
DataView dvGetTribalAdminMailId = new DataView();
dvGetTribalAdminMailId = o_LoginUser.GetTribalAdminMailId();
//string ToEmail = "goldramesh.cool@gmail.com";
if (dvGetTribalAdminMailId.Table.Rows.Count != 0)
{
for (int k = 0; k < dvGetTribalAdminMailId.Table.Rows.Count; k++)
{
DataView dvFamily = new DataView();
dvFamily = o_LoginUser.GetFamily(ParentId);
DataView dvUser = new DataView();
dvUser = o_LoginUser.GetAdult(CurrentUserId);
if (dvFamily.Table.Rows.Count != 0 && dvUser.Table.Rows.Count != 0)
{
int PARENT_ID = Convert.ToInt32(dvFamily[0]["PARENT_ID"].ToString());
string ParentFirstName = dvFamily[0]["PARENT_FIRST_NAME"].ToString();
string PARENT_LAST_NAME = dvFamily[0]["PARENT_LAST_NAME"].ToString();
string PARENT_PHONE_NUMBER = dvUser[0]["CELL_NUMBER"].ToString();
string PARENT_NASS_REF = dvFamily[0]["PARENT_NASS_REF"].ToString();
string PARENT_NI_NUMBER = dvFamily[0]["PARENT_NI_NUMBER"].ToString();
string PARENT_GENDER = dvFamily[0]["PARENT_GENDER"].ToString();
Authentication objAuthentication = new Authentication();
DateTime AddedDate = System.DateTime.Now;
DataView dvNINASSNumber = new DataView();
string UserName = HttpContext.Current.User.Identity.Name.Split('|')[0];
StringBuilder sbSubject = new StringBuilder();
StringBuilder sbBody = new StringBuilder();
sbSubject.Append("Profile Update");
sbBody.Append("<div> Dear Admin,</div>");
sbBody.Append("<br/>");
sbBody.Append("<div> The user" +" "+ ParentFirstName + " has updated the following details.</div>");
sbBody.Append("<br/>");
sbBody.Append(lblParentdetail.Text);
sbBody.Append("<br/>");
sbBody.Append("<br/>");
sbBody.Append("Previous ParentFirstName =");
sbBody.Append(ParentFirstName);
sbBody.Append("<br/>");
sbBody.Append("New ParentFirstName =");
sbBody.Append(txtFirstName.Text);
sbBody.Append("<br/>");
sbBody.Append("Previous ParentLastName =");
sbBody.Append(PARENT_LAST_NAME);
sbBody.Append("<br/>");
sbBody.Append("New ParentLastName =");
sbBody.Append(txtLastName.Text);
sbBody.Append("<br/>");
sbBody.Append("Previous ParentPhoneNumber =");
sbBody.Append(PARENT_PHONE_NUMBER);
sbBody.Append("<br/>");
sbBody.Append("New ParentPhoneNumber =");
sbBody.Append(txtPhoneNumber.Text);
sbBody.Append("<br/>");
sbBody.Append("Previous ParentNASSREFF =");
sbBody.Append(PARENT_NASS_REF);
sbBody.Append("<br/>");
sbBody.Append("New ParentNASSREFF=");
sbBody.Append(txtNASSReference.Text);
sbBody.Append("<br/>");
sbBody.Append("Previous Parent NI Number =");
sbBody.Append(PARENT_NI_NUMBER);
sbBody.Append("<br/>");
sbBody.Append("New Parent NI Number =");
sbBody.Append(txtNINumber.Text);
sbBody.Append("<br/>");
sbBody.Append("Previous Parent Gender =");
sbBody.Append(PARENT_GENDER);
sbBody.Append("<br/>");
sbBody.Append("New Parent Gender =");
sbBody.Append(ddlGender.SelectedValue);
sbBody.Append("<br/>");
for (int i = 0; i < dvFamily.Table.Rows.Count; i++)
{
sbBody.Append("<br/>");
sbBody.Append("<br/>");
int j = i + 1;
Label lbHeader = new Label();
lbHeader.ID = "lbHeader" + i;
string sb = o_LoginUser.NumberToText(j);
lbHeader.Text = "Children Detail" + sb.ToString().TrimEnd();
lbHeader.Width = 200;
sbBody.Append(lbHeader.Text);
sbBody.Append("<br/>");
sbBody.Append("<br/>");
string ChildFirstName = dvFamily[i]["FIRST_NAME"].ToString();
string ChildMiddleName = dvFamily[i]["MIDDLE_NAME"].ToString();
string ChildrenLastName = dvFamily[i]["LAST_NAME"].ToString();
string ChildrenDOB = dvFamily[i]["DOB"].ToString();
string SchoolName = dvFamily[i]["SCHOOL_NAME"].ToString();
string ChildrenGender = dvFamily[i]["GENDER"].ToString();
sbBody.Append("Previous Children FirstName =");
sbBody.Append(ChildFirstName);
sbBody.Append("<br/>");
sbBody.Append("New Children FirstName =");
string strControlName = "txtChildFirstName" + i;
TextBox objTextBox = (TextBox)pnlChildDetail.FindControl(strControlName);
string str = objTextBox.Text;
sbBody.Append(str);
sbBody.Append("<br/>");
sbBody.Append("Previous Children MiddleName =");
sbBody.Append(ChildMiddleName);
sbBody.Append("<br/>");
sbBody.Append("New Children MiddleName =");
string strtxtChildMiddleName = "txtChildMiddleName" + i;
TextBox objTextBox1 = (TextBox)pnlChildDetail.FindControl(strtxtChildMiddleName);
string str1 = objTextBox1.Text;
sbBody.Append(str1);
sbBody.Append("<br/>");
sbBody.Append("Previous Children LastName =");
sbBody.Append(ChildrenLastName);
sbBody.Append("<br/>");
sbBody.Append("New Children LastName=");
string strtxtChildrenLastName = "txtChildrenLastName" + i;
TextBox objTextBox2 = (TextBox)pnlChildDetail.FindControl(strtxtChildrenLastName);
string strChildrenLastName = objTextBox2.Text;
sbBody.Append(strChildrenLastName);
sbBody.Append("<br/>");
sbBody.Append("Previous Children DOB =");
sbBody.Append(ChildrenDOB);
sbBody.Append("<br/>");
sbBody.Append("New Children DOB =");
string strtxtChildrenDOB = "txtChildrenDOB" + i;
TextBox objTextBox3 = (TextBox)pnlChildDetail.FindControl(strtxtChildrenDOB);
string strChildrenDOB = objTextBox3.Text;
sbBody.Append(strChildrenDOB);
sbBody.Append("<br/>");
sbBody.Append("Previous Children SchoolName =");
sbBody.Append(SchoolName);
sbBody.Append("<br/>");
sbBody.Append("New Children SchoolName =");
string strtxtSchoolName = "txtSchoolName" + i;
TextBox objTextBox4 = (TextBox)pnlChildDetail.FindControl(strtxtSchoolName);
string strSchoolName = objTextBox4.Text;
sbBody.Append(strSchoolName);
sbBody.Append("<br/>");
sbBody.Append("Previous Children Gender =");
sbBody.Append(ChildrenGender);
sbBody.Append("<br/>");
sbBody.Append("New Children Gender =");
string strddlChildrenGender = "ddlChildrenGender" + i;
DropDownList objTextBox5 = (DropDownList)pnlChildDetail.FindControl(strddlChildrenGender);
string strChildrenGender = objTextBox5.Text;
sbBody.Append(strChildrenGender);
sbBody.Append("<br/>");
}
sbBody.Append("<br/> .........<br/>");
sbBody.Append(" <div> Thanks, </div>");
sbBody.Append(" <div> Solihull Metropolitan Borough Council</div>");
string ToEmail = dvGetTribalAdminMailId[k]["EmailId"].ToString();
o_EmailManager.SendMail(UserName, ToEmail, sbSubject.ToString(), sbBody.ToString());
tblError.Visible = true;
lblSuccessMessage.Visible = true;
lblSuccessMessage.ForeColor = System.Drawing.Color.Green;
}
}
}
}
Good luck.Happy coding.....
super........... code
ReplyDeleteU r right
Delete