如何得到gridview中模板列的控件

jianghanfei 2010-09-28 04:56:35
ScriptManager.RegisterClientScriptBlock(this.GridView1.Rows[].FindControl("LinkButton1"), typeof(GridView), "ERROR2", "alert('对不起,这个类别下还有商品存在,你不能删除!')", true);
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete")
{

int id = Convert.ToInt32(e.CommandArgument);
IList<Commodity> comodities = CommodityManager.GetCommoditiesByJewelryTypeId(id);
if (comodities == null || comodities.Count == 0)
{
JewelryTypeManager.DeleteJewelryTypeById(id);
}
else
{
Response.Write("alert('对不起,这个类别下还有商品存在,你不能删除!')");
//ScriptManager.RegisterClientScriptBlock(this.GridView1.Rows[].FindControl("LinkButton1"), typeof(GridView), "ERROR2", "alert('对不起,这个类别下还有商品存在,你不能删除!')", true);
}
}
}
Rows[]中的行号怎么得到?
...全文
157 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jianghanfei 2010-09-28
  • 打赏
  • 举报
回复
beyond_me21:得是得到了 为什么提示框没有显示出来啊
jianghanfei 2010-09-28
  • 打赏
  • 举报
回复
e.CommandArgument获取的是我绑定的Id
Rock870210 2010-09-28
  • 打赏
  • 举报
回复
CommandArgument='<%# ((GridViewRow)Container).RowIndex %>'
e.CommandArgument获取的就是index
wuyq11 2010-09-28
  • 打赏
  • 举报
回复

int index=Convert.ToInt32(e.CommandArgument);
GridViewRow row =GridView1.Rows[index];
string str = gv.DataKeys[index].Value.ToString();
beyond_me21 2010-09-28
  • 打赏
  • 举报
回复
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
GridViewRow row = ((LinkButton)e.CommandSource).Parent.Parent as GridViewRow;//获得双击的那一行,这是关键部分
int id = Convert.ToInt32(e.CommandArgument);
IList<Commodity> comodities = CommodityManager.GetCommoditiesByJewelryTypeId(id);
if (comodities == null || comodities.Count == 0)
{
JewelryTypeManager.DeleteJewelryTypeById(id);
}
else
{
Response.Write("alert('对不起,这个类别下还有商品存在,你不能删除!')");
//ScriptManager.RegisterClientScriptBlock(row.FindControl("LinkButton1"), typeof(GridView), "ERROR2", "alert('对不起,这个类别下还有商品存在,你不能删除!')", true);
}
}
}

62,272

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧