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";
<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";
你在
http://expert.csdn.net/Expert/topic/1208/1208917.xml?temp=.844021里已经回答了如何在html中调用C#的代码现在我想问一下在html中能不能调用在CS中的代码,也就是说,我的C#代码不是写在html的javascript中的?谢了
如果我的C#代码不是写在html中的话,我把button的onclick="UpdateGridData"时(<asp:button id="btn" text="update" runat="Server" onclick="UpdateGridData"/>),它会出现如下的错误:
CS0122: 不可访问“sqglxt.grxx.UpdateGridData(object, System.EventArgs)”,因为它受保护级别限制
这是怎么回事?
{
//....
}
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();
}我试了一下好像库里的数据没有反应呀,可不可以这样放呀