首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

在GridView中 有没有好的方法根据rows中某个字段值确定它可不可以编辑同删除解决办法

2012-02-02 
在GridView中 有没有好的方法根据rows中某个字段值确定它可不可以编辑同删除如GridView表:编辑序号班级学

在GridView中 有没有好的方法根据rows中某个字段值确定它可不可以编辑同删除
如GridView表:
  编辑       序号       班级       学号           学科       分数     删除
  编辑       1             306         22898         9             119       删除
  编辑       2             306         22898         8             139       删除
  编辑       3             306         22898         6             107       删除  
  编辑       4             306         22898         7             110       删除  
  编辑       5             306         22898         5             98         删除  
  编辑       6             306         22898         1             121       删除  

那么我要规定在学科为1的记录不能删除

如何做最好

有啥好的设置方法     大家帮忙




[解决办法]
删除事件里判断一下不就可以了?
[解决办法]
楼上正解.case 后面加个break;就可.
[解决办法]
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex > = 0)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{

Label lbQty = e.Row.Cells[6].FindControl( "lb_Qty ") as Label;
Label lbSet = e.Row.Cells[7].FindControl( "lb_Set ") as Label;

int qty = 0;
int set = 0;
if (lbQty != null && (lbQty.Text.Trim() != " " || lbQty.Text.Trim() != string.Empty) && lbSet != null && (lbSet.Text.Trim() != " " || lbSet.Text.Trim() != string.Empty))
{
qty = Convert.ToInt32(lbQty.Text.Trim());
set = Convert.ToInt32(lbSet.Text.Trim());

if (qty < set)
{
e.Row.BackColor = System.Drawing.Color.Red;
btnChange.Enabled = false;
}
}
else
{
btnChange.Enabled = false;
}


}
}
}
[解决办法]
再RowDataBound事件内判断条件就可以了,
[解决办法]
1.
方法 1 同 sosohehe

2。
方法 2 如下:

<asp:templatefield>
<itemtemplate>


<asp:linkbutton id=btnDelete commandname=delete enabled= ' <%# (int)Eval( "学科 ") != 1 %> '
</itemtemplate>
</asp:templatefield>

[解决办法]
if ((HyperLink)e.Row.FindControl( "hyperlink ") != null)
{
if (e.Row.Cells[15].Text == "待收货 ")
{
((HyperLink)e.Row.FindControl( "hyperlink ")).Text = " <a color= '#333333 '> 待收货 </a> ";
}
else if(e.Row.Cells[15].Text == "已入库 ")
{
((HyperLink)e.Row.FindControl( "hyperlink ")).Text = " <a> <font color= '#000FFF '> 已入库 </font> </a> ";
}
else
{
((HyperLink)e.Row.FindControl( "hyperlink ")).Text = " <Font color= 'red '> 已收货 </Font> ";
((HyperLink)e.Row.FindControl( "hyperlink ")).NavigateUrl = "Javascript:launchmodule(600,450, '../AssetApply4/Asset_InsertDevices.aspx?OrderListID= "+e.Row.Cells[1].Text+ " ',0,0,0) ";
}
} if ((HyperLink)e.Row.FindControl( "hyperlink ") != null)
{
if (e.Row.Cells[15].Text == "待收货 ")
{
((HyperLink)e.Row.FindControl( "hyperlink ")).Text = " <a color= '#333333 '> 待收货 </a> ";
}
else if(e.Row.Cells[15].Text == "已入库 ")
{
((HyperLink)e.Row.FindControl( "hyperlink ")).Text = " <a> <font color= '#000FFF '> 已入库 </font> </a> ";
}
else
{
((HyperLink)e.Row.FindControl( "hyperlink ")).Text = " <Font color= 'red '> 已收货 </Font> ";
((HyperLink)e.Row.FindControl( "hyperlink ")).NavigateUrl = "Javascript:launchmodule(600,450, '../AssetApply4/Asset_InsertDevices.aspx?OrderListID= "+e.Row.Cells[1].Text+ " ',0,0,0) ";
}
}
[解决办法]
在ItemDataBound事件中判断~
Jinglecat(晓风残月 > > 问题需简洁,错误要详细)的方法也可以
[解决办法]
最简便的方式:

在删除或编辑前,判断学科是否为 "1 ":
if (dataGridView.Rows[e.RowIndex].Cells[ "学科 "].Value.ToString().Trim() != "1 ")
{
// 不为 "1 ",删除或编辑
}

热点排行