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

解决方案 »

  1.   

    数据库中是不是有这个字段
      case 字段 when  '1' then '已通过' when ‘0’ then '未通过' end as
      

  2.   

    点击“更改” 更改数据库重新绑定datagrid
      

  3.   

    在单击事件中更改LinkButton按钮的描述文本。
      

  4.   

    不好意思看错了,在点击按钮的事件中获取Iterm的Cell然后来更改Cell中的内容(可能需要重新绑定)。
      

  5.   

    数据库中是不是有这个字段
      case 字段 when  '1' then '已通过' when ‘0’ then '未通过' end as
    ---------------------------------数据库中有这样的字段isForbid
      

  6.   

    现在我这里的bing和Page就弄好了,就差这个LinkButton事件怎么写了
      

  7.   

    同过一个字段的值判断的,如果是1就是通过,0就是未通过<%# (DataBinder.Eval(Container.DataItem, "isPass").ToString() == "1") ? "<font color=green>已通过</font>" : "<font color=red>未通过</font>" %>
      

  8.   

    其实LinkButton就是修改数据库中字段isPass的值,完成后,调用
    ListBind();  //绑定数据
    ShowPaging();  //分页
      

  9.   

    用CommandName吧,在后台更改要好作些
      

  10.   

    <tr>
      <td>
       <asp:LinkButton Runat="server" ID="cmd_Update" CausesValidation="False" CommandName="Edit">
       </asp:LinkButton>
    </td>
    </tr>
      

  11.   

    <asp:datagrid id=dg_Formal runat="server" OnUpdateCommand="dg_Formal_Update" >
    后台:
    public void dg_Formal_Update(object Sender, DataGridCommandEventArgs e)
    {
       //操作...
    }
      

  12.   

    你可以给linkbutton的commandname属性加个值:edit
    那么就可以在datagrid的edit事件当中写代码了
      

  13.   

    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();

    }