【发布时间】:2016-08-04 02:29:44
【问题描述】:
我有一个gridview,我想要做的是当我单击行时获取我想要重新加载特定div 的行的值。有没有办法我可以做到这一点?请帮忙。谢谢。
这是我目前所拥有的
<asp:UpdatePanel ID="UpdatePanel5" runat="server">
<ContentTemplate>
<asp:Label ID="graph_val" runat="server"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel6" runat="server">
<ContentTemplate>
<div class = "prg-dte">
<asp:Label ID="Label1" class = "srch-res" runat="server" >
</asp:Label>
</div>
<div class = "table-grid">
<asp:GridView ID="GridView1" class = "grd-view table table-hover" OnRowDataBound="GridView1_RowDataBound" OnSelectedIndexChanged="Gridview1_OnSelectedIndexChanged" runat="server">
</asp:GridView>
</div>
</ContentTemplate>
</asp:UpdatePanel>
这是我要重新加载的 div
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div id="chartContainer" runat="server" style="height: 150px; width: 100%;">
</div>
</ContentTemplate>
</asp:UpdatePanel>
这是我获取行值的 onclick 函数
Protected Overrides Sub Render(writer As HtmlTextWriter)
For Each r As GridViewRow In GridView1.Rows
If r.RowType = DataControlRowType.DataRow Then
r.Attributes("onmouseover") = "this.style.cursor='pointer';"
r.Attributes("onmouseout") = "this.style.textDecoration='none';"
r.ToolTip = "Click to select row"
r.Attributes("onclick") = Me.Page.ClientScript.GetPostBackClientHyperlink(GridView1, "Select$" & r.RowIndex, True)
End If
Next
MyBase.Render(writer)
End Sub
这是我获取饼图值的 javascript
var pie = 0;
function changepie(val) {
pie = val;
function pageLoad() {
var grpval = document.getElementById('<%=graph_val.ClientID%>');
pie = grpval.innerText;
alert(pie)
}
如果我得到正确的值,警报派只是我的调试方式。 我认为我做错了什么我实际上想让gridview行值将其存储在标签中并传入饼图,但我无法使其工作。
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer",
{
animationEnabled: true,
animationDuration: 1300,
legend: {
verticalAlign: "bottom",
horizontalAlign: "center"
},
data: [
{
indexLabelFontSize: 11,
indexLabelFontFamily: "Monospace",
indexLabelFontColor: "darkgrey",
indexLabelLineColor: "darkgrey",
indexLabelPlacement: "outside",
type: "pie",
background: "#FB404B",
toolTipContent: "{y} - <strong>#percent%</strong>",
dataPoints: [
//{ y: pie, legendText: "" , indexLabel: "PlayStation 3" },
//{ y: 1, legendText: "" , indexLabel: "PlayStation 3" },
{ y: pie, name: "Total Load", legendText: "Total Load" },
{ y: 1, name: "Potential Load", legendText: "Potential Load" },
]
}
]
});
//alert(pie);
chart.render();
}
这就是我从标签获取饼图值的方式
Protected Sub Gridview1_OnSelectedIndexChanged(sender As Object, e As EventArgs) Handles GridView1.SelectedIndexChanged
Dim percent As String = GridView1.SelectedRow.Cells(6).Text
graph_val.Text = percent
ClientScript.RegisterClientScriptBlock(Me.[GetType](), "Script", "changepie(" + graph_val.Text + ");", True)
End Sub
【问题讨论】:
-
我看不到您是如何在此处初始化饼图的。都是变数。
-
实际上我迷路了,我尝试了很多工作。现在不知道我怎样才能让它工作。 :(
-
其实渲染图表有点复杂。它还取决于您使用的图表控件。简单地传递变量不会使其呈现。
-
刚刚编辑了我的答案。包括我如何呈现我的图表。请看一下。谢谢! =)
标签: javascript jquery asp.net vb.net gridview