方法:
[Ajax.AjaxMethod()]
public void hitacc(string nid)
{
int dnid=Convert.ToInt32(nid);
SqlCommand SqlCmd = new SqlCommand();
SqlCmd.Connection = new SqlConnection(ConfigurationSettings.AppSettings["ConnString"]);
SqlCmd.CommandText = "update news set hit=hit+1 where nid="+dnid;
SqlCmd.CommandType = CommandType.Text;
SqlCmd.Connection.Open();
SqlCmd.ExecuteNonQuery();
SqlCmd.Connection.Close();
}js代码:
<script language=javascript>
function abc(e)
{
hitacc(e.id.value);
}
</script>
用js的代码:
<a id=<%# DataBinder.Eval(Container.DataItem, "nid") %> onclick="abc(this);"/a>数据库中没有反应,点击数没有加1啊。
[Ajax.AjaxMethod()]
public void hitacc(string nid)
{
int dnid=Convert.ToInt32(nid);
SqlCommand SqlCmd = new SqlCommand();
SqlCmd.Connection = new SqlConnection(ConfigurationSettings.AppSettings["ConnString"]);
SqlCmd.CommandText = "update news set hit=hit+1 where nid="+dnid;
SqlCmd.CommandType = CommandType.Text;
SqlCmd.Connection.Open();
SqlCmd.ExecuteNonQuery();
SqlCmd.Connection.Close();
}js代码:
<script language=javascript>
function abc(e)
{
hitacc(e.id.value);
}
</script>
用js的代码:
<a id=<%# DataBinder.Eval(Container.DataItem, "nid") %> onclick="abc(this);"/a>数据库中没有反应,点击数没有加1啊。
Ajax.Utility.RegisterTypeForAjax(typeof(SFAjaxMethod));
提示错误是 'undefined'为空或不是对象
<script language=javascript>
function abc(e)
{
hitacc(e.id);
}
</script>试试
<a id=<%# DataBinder.Eval(Container.DataItem, "nid") %> onclick="abc(this);"/a>
中的id的值没有加引号,还有数据库中hit的初始值不能为空,要是个具体的数字才能正确加一,
为了这个问题搞了半天啊。
谢谢大家捧场了!