Click here to Skip to main content
16,007,885 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

In my webpage there are 5 rows of text boxes, user needs to fill data in that on submission these data should be inserted into database.

The problem is all textboxes in each row are mandatory, He might enter data in 1, 2, 3, 4 or all rows.

In code how can i get to know in which row he entered data and how can i pass this into sql database for insertion. i tried putting required feild validators for each textboxes but if user enters only in 2 or 3 rows the remaining row's required feild validators wont validates the page and it wont reach server.

how ever rows user enters data those details must be insreted into database, but each row must be filled.

Please help me to solve this problem.
Posted
Comments
Karthik Harve 26-Dec-11 23:42pm    
have you given proper validation groups for the textboxes..???

1 solution

you can check this at rowdatabound :
C#
protected void grdMain_RowDataBound(object sender, GridViewRowEventArgs e)
{
TextBox textbox1= (TextBox)e.Row.FindControl("txtBox1");
TextBox textbox2= (TextBox)e.Row.FindControl("txtBox2");

// so on...

if(txtbox1.Text=="")
{
// print error msg or show any dynamic msg when validation required for txtbox1.
}
else if(txtBox2.Text=="")
{
// print error msg or show any dynamic msg when validation required for txtbox2.
}
else
{
// so on....
}
}

After check the row , you can insert into database.
Hope this will help you.
Don't forget to mark as answer if it helps. :)
 
Share this answer
 
v2
Comments
Suraj S Koneri 27-Dec-11 1:01am    
Thanks for the answer but in your code, you are using grid view but i've controlls in HTML table.
And the u used the find control method to find textboxes, which most error prone thing,.. sometimes it throws you null reference exceptions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900