following your design, add a hidden input control<form runat="server">
<input type="hidden" id="DGID" runat="server"/>
<asp:button id="btn" text="update" runat="Server" onclick="UpdateGridData"/>
</form>
.......
<script language="javascript">
function GridPostBack(index)
{
 document.forms[0].DGID.value = index;
 document.forms[0].btn.click();
}
</script>
<script language="C#" runat="Server">
void UpdateGridData(Object sender, EventArgs e)
{
  string ID = DGID.Value;
//update here
}
</script>you could make the button invisible in Page_Load:
btn.Style["display"] = "none";

解决方案 »

  1.   

    to saucer(思归) :
    你在
    http://expert.csdn.net/Expert/topic/1208/1208917.xml?temp=.844021里已经回答了如何在html中调用C#的代码现在我想问一下在html中能不能调用在CS中的代码,也就是说,我的C#代码不是写在html的javascript中的?谢了
      

  2.   

    same, the server side code is processed by ASP.NET, it does not care whether you are using code code-behind or not
      

  3.   

    to saucer(思归):
       如果我的C#代码不是写在html中的话,我把button的onclick="UpdateGridData"时(<asp:button id="btn" text="update" runat="Server" onclick="UpdateGridData"/>),它会出现如下的错误:
    CS0122: 不可访问“sqglxt.grxx.UpdateGridData(object, System.EventArgs)”,因为它受保护级别限制
    这是怎么回事?
      

  4.   

    in your page class, add "protected" before the function definition:protected void UpdateGridData(Object sender, EventArgs e)
    {
    //....
    }
      

  5.   

    to saucer(思归) 兄:   非常感谢你的答复,现在我还有一个问题,就是我能不能不用btn的click事件,而直接把更新代码放到函数中:
    function GridPostBack(index)
    {
     document.forms[0].DGID.value = index;
    string ID = DGID.Value;
    string strupdateQuery="update 参数表 set 记录号='"+ID+"'";
    SqlConnection sqlCnnt = new SqlConnection("server=localhost;Trusted_Connection=true;database=sqglxt");
    sqlCnnt.Open(); 
    SqlCommand sqlcmdUpdate = new SqlCommand(strupdateQuery,sqlCnnt);
    sqlcmdUpdate.ExecuteNonQuery(); 
    sqlCnnt.Close();
    }我试了一下好像库里的数据没有反应呀,可不可以这样放呀
      

  6.   

    do you know the difference between client side code and server side code?