我有一个标签,我通过后端编码存储了它的值。我想获得标签的价值并传递给Javascript。请帮帮我。一切都可以找到,但是当我添加更新面板时,它们现在显示0值。我需要更新面板,以便页面不会刷新每个gridview行点击。标签值传递给javascript
这是我到目前为止。
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="my_graph" runat="server"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel4" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" class = "grd-view table table-hover" OnRowDataBound="GridView1_RowDataBound" OnSelectedIndexChanged="Gridview1_OnSelectedIndexChanged" runat="server">
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<div id="chartContainer" style="height: 150px; width: 100%;"></div>
的JavaScript
var pie = 0;
function changepie(val) {
pie = val;
}
function pageLoad() {
alert(pie)
}
后端
Protected Sub Gridview1_OnSelectedIndexChanged(sender As Object, e As EventArgs) Handles GridView1.SelectedIndexChanged
Dim percent As String = GridView1.SelectedRow.Cells(6).Text
my_graph.Text = percent
ClientScript.RegisterClientScriptBlock(Me.[GetType](), "Script", "changepie(" + my_graph.Text + ");", True)
End Sub
只要给它一个ID,并把它 –
@RachitGupta什么你的意思是?你能给我一个样品吗?谢谢。 –
学习JS的基本语法。 –