asp.net中能不能在GridView加个ItemTemplate,ItemTemplate里是个Button,然后点击那个Button就知道点了哪行? 想了很久也不知道怎样在点击事件那里获取点了那行的索引 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 例如你的模板列Button在第5列,(从0算),名称为Button1 在GridView1的RowDataBound事件中的代码: protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { ((Button)e.Row.Cells[5].FindControl("Button1")).CommandArgument = e.Row.RowIndex.ToString(); } } 在Button1的click事件中获得行号: protected void Button1_Click(object sender, EventArgs e) { Button myL = (Button)sender; string no = myL.CommandArgument.ToString(); //no是你要的行号 } 点击事件响应的是RowCommand方法。在这个方法里处理点击事件。处理的方法好几种,比如你可以把索引值标在GridView里面的一个Label字段里,可以隐藏这个Label.然后点击事件后,在RowCommand里搜索这个Label,获取它的Text值就可以了 第二种方法:1.添加模板列Button在第5列,(从0算),名称为Button1,2.设置Button1的CommandName属性等于"Select";3.在GridView1的SelectedIndexChanged事件中获取行号: protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { string no = GridView1.SelectedIndex.ToString();//no是你要的行号 } 按钮加CommandArgument="<%#((GridViewRow)Container).RowIndex%>" 网站微缩图 求助 IIS 设置达人,关于【反射】权限问题 用过URLRewriter的进来看下,如何配置这两个参数的正则表达 网页底部的空白区域出现了拖影,求教解决方案 大家帮我看看我的缓存依赖写对了没? 谁知道怎么把Visio数据库模型图转成SQL SERVER的真实表. 我有个问题难死我了,请高手解答下 急问如何copy datatable---waiting!!!! 谁能讲一下怎么用vs.net调试asp.net程序? 数据库图象显示在网页的固定位置问题? 怎么样用JavaScript删除ItemTemplate 中的一行? 关于ERP系统的开发
在GridView1的RowDataBound事件中的代码:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
((Button)e.Row.Cells[5].FindControl("Button1")).CommandArgument = e.Row.RowIndex.ToString();
}
} 在Button1的click事件中获得行号:
protected void Button1_Click(object sender, EventArgs e)
{
Button myL = (Button)sender;
string no = myL.CommandArgument.ToString(); //no是你要的行号
}
处理的方法好几种,比如你可以把索引值标在GridView里面的一个Label字段里,可以隐藏这个Label.然后点击事件后,在RowCommand里搜索这个Label,获取它的Text值就可以了
1.添加模板列Button在第5列,(从0算),名称为Button1,
2.设置Button1的CommandName属性等于"Select";
3.在GridView1的SelectedIndexChanged事件中获取行号:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
string no = GridView1.SelectedIndex.ToString();//no是你要的行号
}