zameer21
asked on
Gridview item template text box validation
Asp.net Gridview:I have Gridview being pupulated by Product and Unit Price from database and i also have item templelate that has a text box for quanity and another item template for button which says "Add to cart".Now i want to add validation to the button,that it checks that quanity textbox is required and also a integer.How can i do it at a gridview row level
ASKER
I tried that but that does validation to whole gridview but not to the row on which the button was pressed.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
here is what i would do
protected void dg_ItemDataBound()
{
if (e.row.rowtype == rowtype.datarow)
{
// reference the controls
RequiredFieldValidtor reqv = (RequiredFieldValididator) e.row.find control("r eqV");
.. any other validators you may need ...
TextBox unitprice = (textbox)e.row.findcontrol ("txtb");
reqv.controltovalidate = unitprice.id;
{
an approach like this will work, i didnt build this in vs so the syntax is a little off, but you need to hook this event handler up to the gridview.ItemDataBound or RowDataBound i believe.
Any questions let me know
protected void dg_ItemDataBound()
{
if (e.row.rowtype == rowtype.datarow)
{
// reference the controls
RequiredFieldValidtor reqv = (RequiredFieldValididator)
.. any other validators you may need ...
TextBox unitprice = (textbox)e.row.findcontrol
reqv.controltovalidate = unitprice.id;
{
an approach like this will work, i didnt build this in vs so the syntax is a little off, but you need to hook this event handler up to the gridview.ItemDataBound or RowDataBound i believe.
Any questions let me know
ASKER
Thats was cool Valkyrie,I was not able to verify Rodmjay's answer.
Just for fun, here's a good review of ASP.Net validators: http://www.codeproject.com/aspnet/aspnetvalidation.asp
hth
valkyrie_nc