2

我有一个Repeater我将一些数据绑定到它。现在我的问题是如何从javascript. 我的代码如下;

代码隐藏

protected void Page_Load(object sender, EventArgs e)
 {

 // bool boolfound = false;
 string connstring = String.Format("Server=localhost; Port=5432; User Id=postgres; Password=database; Database=valletta;");

 using (NpgsqlConnection conn = new NpgsqlConnection(connstring))
 {
  try
   {
    conn.Open();

    NpgsqlCommand cmd = new NpgsqlCommand("select get_points('temp_intersect', 'point','id',17339)", conn);
    NpgsqlDataReader dr = cmd.ExecuteReader();

    currentpoint.DataSource = dr;
    currentpoint.DataBind();

   }
   catch (Exception)
   {
    ClientScript.RegisterStartupScript(this.GetType(), "", "$(document).ready(function(){alert('problem with connection')});", true);
   }
 }

}

ASP

<asp:Repeater ID="currentpoint" runat="server">
   <ItemTemplate>
     <div>
       <asp:Label ID="hiddenlabel" runat="server" Text='<%# Eval("get_points")%>' Visible="false">
       </asp:Label>
      </div>
    </ItemTemplate>
 </asp:Repeater>
4

2 回答 2

3

您可以将 ClientIDMode 更改为 Predictable 或 static,适用于 javascript。

阅读这篇文章

于 2013-02-21T22:06:44.777 回答
1

试试这个:

document.getElementById('<%=currentpoint.FindControl("hiddenlabel").ClientID%>')
于 2013-02-21T23:54:59.790 回答