Hi.....
I am creating a data table dynamically which has 10 rows and binding that table to Gridview.
In Gridview, I am having 4 dropdownlist, 5 textbox and 1 label controls .
here i want to give clientside validations using javascript for textbox but I am unable to find the textbox control of a gridview using javascript.
please help..
Loading

Manikavelu VelayuthamRank #413 · 6K reputationPosted Dec 9, 2010, 9:53 PM EST
http://www.c-sharpcorner.com/uploadfile/purankaushal/gridjavascript05212008014115am/gridjavascript.aspx
Another way.
1. Find the textbox control in the RowDataBound or ItemDataBound event of the grid view.
2. Add the attributes to that textbox like.. Textbox1.Attributes.Add("OnClick", "Javascript function name");
3. In the javasscript function, you can implement your client side validation.
CrishRank #1,487 · 1.1K reputationPosted Dec 10, 2010, 12:32 AM EST
I had same problem.You have to check following code i think it will help you.
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class Temp : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //Create dummy data DataTable dt = new DataTable(); dt.Columns.Add("ChargeCode"); dt.Columns.Add("ChargeAmount"); dt.Columns.Add("StopNumber"); Session["ChargeDataTable"] = dt; //Bind the gridview BindGrid(); } //Recurses through the controls to show the naming of each individual control that is currently in the gridview //RecurseControls(GridView1.Controls[0].Controls); //Label1.Text += GridView1.Controls[0].Controls[0].GetType().Name + " "; } void RecurseControls(ControlCollection ctls) { foreach (Control ctl in ctls) { if (!ctl.HasControls()) Label1.Text += ctl.ClientID + " " + ctl.GetType().Name + "<br />"; else RecurseControls(ctl.Controls); } } void BindGrid() { DataTable dt = new DataTable(); dt = (DataTable)Session["ChargeDataTable"]; //Bind the gridview GridView1.DataSource = dt; GridView1.DataBind(); } void AddNewCharge(string ChargeCode, string ChargeAmount, string StopNumber) { DataTable dt = new DataTable(); dt = (DataTable)Session["ChargeDataTable"]; DataRow dr = dt.NewRow(); dr["ChargeCode"] = ChargeCode; dr["ChargeAmount"] = ChargeAmount; dr["StopNumber"] = StopNumber; dt.Rows.Add(dr); Session["ChargeDataTable"] = dt; BindGrid(); } protected void GridView1_RowCommand1(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "EmptyInsert") { //handle insert here TextBox ChargeCode = GridView1.Controls[0].Controls[0].FindControl("txtChargeCodeEmptyInsert") as TextBox; TextBox ChargeAmount = GridView1.Controls[0].Controls[0].FindControl("txtChargeAmountEmptyInsert") as TextBox; TextBox StopNumber = GridView1.Controls[0].Controls[0].FindControl("txtStopNumberEmptyInsert") as TextBox; AddNewCharge(ChargeCode.Text, ChargeAmount.Text, StopNumber.Text); //Label1.Text = string.Format("You would have inserted the name : {0} from the emptydatatemplate",tbEmptyInsert.Text); } if (e.CommandName == "Insert") { //handle insert here TextBox ChargeCode = GridView1.FooterRow.FindControl("txtChargeCodeInsert") as TextBox; TextBox ChargeAmount = GridView1.FooterRow.FindControl("txtChargeAmountInsert") as TextBox; TextBox StopNumber = GridView1.FooterRow.FindControl("txtStopNumberInsert") as TextBox; AddNewCharge(ChargeCode.Text, ChargeAmount.Text, StopNumber.Text); //Label1.Text = string.Format("You would have inserted the name : {0} from the footerrow", tbInsert.Text); } } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; BindGrid(); } If you want to get more detail about this code than just go for this below link. http://forums.asp.net/t/1204756.aspx }