J
Jason
Please could you help?
I have 2 textboxes in a gridview EditItemTemplate. These are template
controls. When I type in the "Amount" textbox I want to fill in the "Percent"
textbox
************************************************************
Here's my markup, which successfully fires the javascript
<asp:TemplateField HeaderText="Increase">
<EditItemTemplate>
<asp:TextBox
ID="SalaryIncreaseAmountTextBox" runat="server" Text='<%#
Bind("SalaryIncreaseAmount") %>' onblur="MyJSFunc()"> </asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server"
Text='<%# Bind("SalaryIncreaseAmount","{0:N0}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Increase %"
SortExpression="PercentIncrease">
<EditItemTemplate>
<asp:TextBox ID="PercentIncreaseTextBox"
runat="server" Text='<%# Bind("PercentIncrease") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server"
Text='<%# Bind("PercentIncrease","{0:N2}") %>'></asp:Label>
</ItemTemplate>
<ControlStyle Width="30px" />
<HeaderStyle HorizontalAlign="Right" />
<ItemStyle HorizontalAlign="Right" />
</asp:TemplateField>
**********************************************************
here's my javascript:
function MyJSFunc() {
var pc =
document.getElementById("grdApproval_PercentIncreaseTextBox");
var amt =
document.getElementById("grdApproval_SalaryIncreaseAmountTextBox");
var sal = document.getElementById("grdApproval_SalaryLabel");
pc.value = amt.value / sal.value.replace(",", "") * 100;
}
**********************************************************
The problem is that getElementById doesn't find anything
I have tried writing codebehind like this:
Private Sub grdApproval_RowEditing(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewEditEventArgs) Handles
grdApproval.RowEditing
Dim r As GridViewRow
r = grdApproval.Rows(e.NewEditIndex)
DirectCast(r.FindControl("SalaryIncreaseAmountTextBox"),
TextBox).Attributes.Add("onblur", "MyJSFunc(" &
DirectCast(r.FindControl("PercentIncreaseTextBox"), TextBox).ClientID & ")")
End Sub
*********************************************************
Now the FindControl returns nothing.
I dig around inside the GridViewRow and all I can find is things like this:
? r.Controls(7)
{System.Web.UI.WebControls.DataControlFieldCell}
System.Web.UI.WebControls.DataControlFieldCell:
{System.Web.UI.WebControls.DataControlFieldCell}
AppRelativeTemplateSourceDirectory: "~/"
BindingContainer: {System.Web.UI.WebControls.GridViewRow}
ClientID: "grdApproval_ctl02_ctl02"
Controls: {System.Web.UI.ControlCollection}
EnableTheming: True
EnableViewState: True
ID: "ctl02"
NamingContainer: {System.Web.UI.WebControls.GridViewRow}
Page: {ASP.approvalpage_aspx}
Parent: {System.Web.UI.WebControls.GridViewRow}
Site: Nothing
SkinID: ""
TemplateControl: {ASP.approvalpage_aspx}
TemplateSourceDirectory: "/"
UniqueID: "grdApproval$ctl02$ctl02"
Visible: True
and I can't find anything that looks like a textbox
I have 2 textboxes in a gridview EditItemTemplate. These are template
controls. When I type in the "Amount" textbox I want to fill in the "Percent"
textbox
************************************************************
Here's my markup, which successfully fires the javascript
<asp:TemplateField HeaderText="Increase">
<EditItemTemplate>
<asp:TextBox
ID="SalaryIncreaseAmountTextBox" runat="server" Text='<%#
Bind("SalaryIncreaseAmount") %>' onblur="MyJSFunc()"> </asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server"
Text='<%# Bind("SalaryIncreaseAmount","{0:N0}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Increase %"
SortExpression="PercentIncrease">
<EditItemTemplate>
<asp:TextBox ID="PercentIncreaseTextBox"
runat="server" Text='<%# Bind("PercentIncrease") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server"
Text='<%# Bind("PercentIncrease","{0:N2}") %>'></asp:Label>
</ItemTemplate>
<ControlStyle Width="30px" />
<HeaderStyle HorizontalAlign="Right" />
<ItemStyle HorizontalAlign="Right" />
</asp:TemplateField>
**********************************************************
here's my javascript:
function MyJSFunc() {
var pc =
document.getElementById("grdApproval_PercentIncreaseTextBox");
var amt =
document.getElementById("grdApproval_SalaryIncreaseAmountTextBox");
var sal = document.getElementById("grdApproval_SalaryLabel");
pc.value = amt.value / sal.value.replace(",", "") * 100;
}
**********************************************************
The problem is that getElementById doesn't find anything
I have tried writing codebehind like this:
Private Sub grdApproval_RowEditing(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewEditEventArgs) Handles
grdApproval.RowEditing
Dim r As GridViewRow
r = grdApproval.Rows(e.NewEditIndex)
DirectCast(r.FindControl("SalaryIncreaseAmountTextBox"),
TextBox).Attributes.Add("onblur", "MyJSFunc(" &
DirectCast(r.FindControl("PercentIncreaseTextBox"), TextBox).ClientID & ")")
End Sub
*********************************************************
Now the FindControl returns nothing.
I dig around inside the GridViewRow and all I can find is things like this:
? r.Controls(7)
{System.Web.UI.WebControls.DataControlFieldCell}
System.Web.UI.WebControls.DataControlFieldCell:
{System.Web.UI.WebControls.DataControlFieldCell}
AppRelativeTemplateSourceDirectory: "~/"
BindingContainer: {System.Web.UI.WebControls.GridViewRow}
ClientID: "grdApproval_ctl02_ctl02"
Controls: {System.Web.UI.ControlCollection}
EnableTheming: True
EnableViewState: True
ID: "ctl02"
NamingContainer: {System.Web.UI.WebControls.GridViewRow}
Page: {ASP.approvalpage_aspx}
Parent: {System.Web.UI.WebControls.GridViewRow}
Site: Nothing
SkinID: ""
TemplateControl: {ASP.approvalpage_aspx}
TemplateSourceDirectory: "/"
UniqueID: "grdApproval$ctl02$ctl02"
Visible: True
and I can't find anything that looks like a textbox