how to pass gridview textbox value to javascript
-
Hi I am using gridview in one page and wanted to do some calculation, for this i wanted to pass textbox values to javascript, kindly help me if anyone knows how to pass gridview textbox value to java script. Thanks in advance
You can access the grid view's text boxes from javascript by using the controls client id. it will generally be in the patter gridid$controlid$slno. You can get this by viewing the client HTML source on the browser.
-
You can access the grid view's text boxes from javascript by using the controls client id. it will generally be in the patter gridid$controlid$slno. You can get this by viewing the client HTML source on the browser.
-
I don't have access to VS 2005 or greater at work so here is a sample with VS 2003/ASP.NET 1.x - For this datagrid
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 102; LEFT: 208px; POSITION: absolute; TOP: 160px" runat="server" AutoGenerateColumns="False"> <Columns> <asp:TemplateColumn HeaderText="sd" FooterText="as"> <ItemTemplate> <asp:TextBox ID="abc" Runat="server" Text="asd"></asp:TextBox> </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:DataGrid>
and this code
DataTable asd = new DataTable("asd"); asd.Columns.Add("asd"); DataRow dr = asd.NewRow(); DataRow dr1 = asd.NewRow(); dr\[0\]=asd; dr1\[0\]=asd; asd.Rows.Add(dr); asd.Rows.Add(dr1); DataGrid1.DataSource= asd; DataGrid1.DataBind();
the client ids for the 2 text boxes generated would be
DataGrid1__ctl2_abc
andDataGrid1__ctl3_abc
You can use this id in the getElementById method in javascript to access the data. NOTE - Client id generated in higher version of ASP.NET will be similar but not exactly the same.