为每个单元格加上onclick事件,单击并调用客服端tt函数
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 2; i < e.Row.Cells.Count - 1; ++i)
{
e.Row.Cells[i].Attributes.Add("onclick", "tt('"+e.Row.RowIndex+"','"+i+"')");
e.Row.Cells[i].Attributes["style"] += "cursor:pointer;cursor:hand;";
}
}
}
<script language="javascript" >
function tt(R,C)
{
(document.all["GridView1"]).Rows[R].Cells[C].add(document.all["TextBox1"]);
}
</script>
错误提示:document.all.GridView1.Rows为空或者不是对象。
请问这样写错了哪里
还是不能这样用的。
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 2; i < e.Row.Cells.Count - 1; ++i)
{
e.Row.Cells[i].Attributes.Add("onclick", "tt('"+e.Row.RowIndex+"','"+i+"')");
e.Row.Cells[i].Attributes["style"] += "cursor:pointer;cursor:hand;";
}
}
}
<script language="javascript" >
function tt(R,C)
{
(document.all["GridView1"]).Rows[R].Cells[C].add(document.all["TextBox1"]);
}
</script>
错误提示:document.all.GridView1.Rows为空或者不是对象。
请问这样写错了哪里
还是不能这样用的。
解决方案 »
- 去掉HTML代码的问题?
- 倒,不能结帖子,有人去接分吗?
- asp.net中Calendar个头好大啊,能不能设置成winform中TimePicker小个子类型的
- 购物车返回页面地址怎么做好一点?
- 有关网站的日志????
- 手动测试触发器可以执行,但是在程序执行中没有反应
- CrystalDecisions.Shared.DLL这个文件谁能提供一份啊?它是作甚么用的呢?
- 数据绑定问题?
- 如何实现控件的点击事件,请求帮助!
- vb中的request.cookies("cookiename") is Nothing是什么意思?用c#怎么表示?
- if语句不执行。。。请帮忙看看
- oracle的学习目标是什么呢
最好把解析出来的gridview也贴上看看。
<tr>
<th scope="col" style="width:1000px;">j</th><th scope="col" style="width:1000px;">jj</th><th scope="col" style="width:1000px;">d</th><th scope="col" style="width:1000px;">dd</th><th scope="col" style="width:1000px;">asd</th><th scope="col" style="width:1000px;">asdf</th>
</tr><tr>
<td>4</td><td>3</td><td onclick="tt('0','2')" style="cursor:pointer;cursor:hand;">222</td><td onclick="tt('0','3')" style="cursor:pointer;cursor:hand;">333</td><td onclick="tt('0','4')" style="cursor:pointer;cursor:hand;">888</td><td> </td>
</tr><tr>
<td>6</td><td>2</td><td onclick="tt('1','2')" style="cursor:pointer;cursor:hand;">333</td><td onclick="tt('1','3')" style="cursor:pointer;cursor:hand;"> </td><td onclick="tt('1','4')" style="cursor:pointer;cursor:hand;"> </td><td> </td>
</tr><tr>
<td>6</td><td>3</td><td onclick="tt('2','2')" style="cursor:pointer;cursor:hand;">5566</td><td onclick="tt('2','3')" style="cursor:pointer;cursor:hand;"> </td><td onclick="tt('2','4')" style="cursor:pointer;cursor:hand;"> </td><td> </td>
</tr>
</table>
的代码
var table=document.all["GridView1"];
table.rows[R].cell[C]这是存在的,但是table.rows[R].cell[C].add(document.all["TextBox1"])这个方法是不存在的 建议:可将该table.rows[].cell[]中单元格的值获取出来,然后修改该单元格的innerhtml
修改完后好像不能更新到服务器table.rows[R].cell[C].text
页面重载后table.rows[R].cell[C].text的值变回原来的值
绑定是在If(!ispostback){this.GridView1.DataBind();}中绑定的