my Question is that,
i am applying runtime regular expression validation on textbox which was bounded with gridview and its working correctly but the problem is that data is being submitted after occuering validation and thats not i want or thats not should be
my code is below:
Project1TableAdapter loadProject;
ProjectAnswerTableAdapter insertAnswer;
string data;
int qid = 18;
protected void Page_Load(object sender, EventArgs e)
{
loadProject = new Project1TableAdapter();
if (!Page.IsPostBack)
{
ddlProject.DataTextField = "projectName";
ddlProject.DataValueField = "project_official_id";
ddlProject.DataSource = loadProject.GetProject();
ddlProject.DataBind();
ddlProject.Items.Insert(0, "Select Project");
//Validation();
}
Validation();
}
private void Validation()
{
foreach (GridViewRow gvr in GridView1.Rows)
{
if (qid == Convert.ToInt32(gvr.Cells[0].Text))
{
RegularExpressionValidator regEx = new RegularExpressionValidator();
regEx.ID = "RegularExpressionValidator1";
regEx.ControlToValidate = "txtAnswer";
regEx.ValidationExpression = @"\d{2}\/\d{2}\/\d{4}";
regEx.ErrorMessage = "Date is not Valid";
regEx.SetFocusOnError = true;
gvr.Cells[3].Controls.Add(regEx);
}
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
insertAnswer = new ProjectAnswerTableAdapter();
//Validation();
foreach (GridViewRow gvr in GridView1.Rows)
{
data = ((TextBox)gvr.Cells[2].FindControl("txtAnswer")).Text;
string questionID = gvr.Cells[0].Text;
Response.Write("
" + data + " ID is : " + questionID.ToString());
" + data + " ID is : " + questionID.ToString());
//Validation();
}
}
please Reply Soon
Thanks.
please Reply Soon
Thanks.
Jiteendra SampathiraoPosted Jul 11, 2011, 2:11 AM
after occurring validation the value will be added to gridview...because of you mentioned this code....
gvr.Cells[3].Controls.Add(regEx);
so separate this functionalities..
Faisal AnsariPosted Jul 11, 2011, 2:52 AM
Thanks :)
Faisal AnsariPosted Jul 11, 2011, 2:24 AM
thanks for reply :)
how can i seperate this please do me little favour and do seperate this for me
i'll be thankful to you