日期:2014-05-19  浏览次数:20450 次

紧急求助:DataGrid中LinkButton的使用方法
DataGrid如下所示:
-------------------------------
...   |     是否通过   |       更改权限     |                         为标题栏
-------------------------------
...   |     未通过       |           更改         |                         为数据栏
-------------------------------
...   |     已通过       |           更改         |                        
-------------------------------

其中“更改”是   LinkButton   按钮,如何实现我点击   “更改”   按钮时,让其前面的“是否通过”状态在“已通过”和“未通过”之间相互转换,也就是说如果现在的状态是   “未通过”,我点击一次   “更改”按钮,那么状态就显示“已通过”,再点击一次,就变回   “未通过”。请问点击LinkButton按钮的过程怎么写,才能实现上述功能?
注:请不要用HyperLink来处理,这种方法我已经实现了上述功能。

谢谢各位了。

------解决方案--------------------
数据库中是不是有这个字段
case 字段 when '1 ' then '已通过 ' when ‘0’ then '未通过 ' end as
------解决方案--------------------
点击“更改” 更改数据库重新绑定datagrid

------解决方案--------------------
在单击事件中更改LinkButton按钮的描述文本。
------解决方案--------------------
不好意思看错了,在点击按钮的事件中获取Iterm的Cell然后来更改Cell中的内容(可能需要重新绑定)。
------解决方案--------------------
绑定数据的时候显示 "未通过 ", "已通过 "

操作后(更新后)重新绑定.

------解决方案--------------------
这个 "未通过 " "已通过 "是普通的文字?
------解决方案--------------------
用CommandName吧,在后台更改要好作些
------解决方案--------------------
你可以给linkbutton的commandname属性加个值:edit
那么就可以在datagrid的edit事件当中写代码了
------解决方案--------------------
private void Datagrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{

int i=e.Item.ItemIndex;
string id=this.Datagrid1.DataKeys[i].ToString();
string myQuery= " ";
string mycondition= " ";

SqlConnection myConnection = new SqlConnection(myCS);
myConnection.Open();
myQuery = "SELECT [Condition] from [SM_User] where id= ' "+id+ " ' ";

SqlCommand myCommand= new SqlCommand(myQuery,myConnection);
SqlDataReader objDataReader=myCommand.ExecuteReader();

if(objDataReader.Read())
{

if(!objDataReader.IsDBNull(0))
mycondition=objDataReader.GetString(0).Trim();
if(mycondition.Trim()== "已通过 ")
mycondition= "未通过 ";
else
mycondition= "已通过 ";

}

objDataReader.Close();

//

myQuery= "update [SM_user] set condition= ' "+mycondition+ " ' ";
myQuery+= " WHERE [ID]= ' "+ id + " ' ";

myCommand= new SqlCommand(myQuery,myConnection);


myCommand.ExecuteNonQuery();
if(myConnection.State == ConnectionState.Open)myConnection.Close();


Bind();