How TO get datagrid textbox value in javascript

Posted by Naveenrohillamca under ASP.NET on 5/16/2013 | Points: 10 | Views : 3768 | Status : [Member] | Replies : 2
Help please
when at run time i enter some value in txtA and Move to next control it gives run time error object required on the design of form on "on blur" event
 Design Code
<asp:DataGrid ID="datagrid1" runat="server" DataSourceID="SqlDataSource1">
<Columns>
<asp:TemplateColumn >
<ItemTemplate>
<asp:TextBox ID="txtA" runat="server" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn >
<ItemTemplate>
<asp:TextBox ID="txtB" runat="server""></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:TextBox ID="txtC" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.QTY") %>'
></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

VB.NET CODE Behind Code
Private Sub datagrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles datagrid1.ItemDataBound
If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
Dim tempQtyTbClientId As String
Dim tempAmmtTbClientId As String
tempQtyTbClientId = CType(e.Item.FindControl("txtProgress"), TextBox).ClientID.ToString
tempAmmtTbClientId = CType(e.Item.FindControl("txtCummVolume"), TextBox).ClientID.ToString
CType(e.Item.FindControl("txtProgress"), TextBox).Attributes.Add("onblur", "fnValidateAmount(this, " & tempQtyTbClientId & ");")

End If

End Sub


Javascript Code

function fnValidateAmount()
{
var argu= fnValidateAmount.arguments;
s = (document.forms(0).elements("txtA").value)
n = (document.forms(0).elements("txtC").value)
if ((document.forms(0).elements("txtA").value!= "") && (document.forms(0).elements("txtC").value!=""))
{
a = (eval(document.forms(0).elements("txtA").value)) + (eval(document.forms(0).elements("txtC").value))
document.forms(0).elements("txtB").value = a.toFixed(2);
(document.forms(0).elements("txtC").value) = n
}

if ((document.forms(0).elements("txtA").value == "") && (document.forms(0).elements("txtC").value!=""))
{
(document.forms(0).elements("txtB").value)=(document.forms(0).elements("txtC").value)
}

if ((document.forms(0).elements("txtA").value!="") && (document.forms(0).elements("txtC").value == ""))
{
(document.forms(0).elements("txtB").value) = (document.forms(0).elements("txtA").value)
}
return true
}




Responses

Posted by: aswinialuri-19361 on: 5/17/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Naven,

I hope it will help you try this below link
http://www.codeproject.com/Questions/122106/textbox-in-gridview-control-using-javascript
http://forums.asp.net/t/1172650.aspx/1

Thanks&Regards


Mark as Answer if it helps you
Thanks&Regards
Aswini Aluri

Naveenrohillamca, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naveenrohillamca on: 5/22/2013 [Member] Starter | Points: 25

Up
0
Down
Thanks you solve my problem but i m using external javascript and how do i get the id of text box in that

stdate = document.forms(0).elements("txt1").value;
if(stdate == "")
{
alert("Field can't be blank!");
document.forms(0).elements("txt1").focus();
return (false);
}

Naveenrohillamca, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response