看我如下代码:            for (int i = 0; i < dsDest.Tables[0].Rows.Count - 1; i++)
            {
                switch (Int32.Parse(dgvDestTbl.Rows[1].Cells[1].Value.ToString()))
                {
                    case 56:
                        dgvDestTbl.Rows[i].Cells[1].Value == "int(" + dsDest.Tables[0].Rows[i][5].ToString() + ")";
                        break;
                    case 61:
                        dgvDestTbl.Rows[i].Cells[1].Value == "datetime";
                        break;
                    case 231:
                        dgvDestTbl.Rows[i].Cells[1].Value == "nvarchar(" + dsDest.Tables[0].Rows[i][5].ToString() + ")";
                        break;
                    case 167:
                        dgvDestTbl.Rows[i].Cells[1].Value == "varchar(" + dsDest.Tables[0].Rows[i][5].ToString() + ")";
                        break;
                    case 52:
                        dgvDestTbl.Rows[i].Cells[1].Value == "smallint(" + dsDest.Tables[0].Rows[i][5].ToString() + ")";
                        break;
                    case 108:
                        dgvDestTbl.Rows[i].Cells[1].Value == "numeric(" + dsDest.Tables[0].Rows[i][5].ToString() + ")";
                        break;
                }
            }下面是错误,是不是说不能把String赋值给Datagridview的单元格呢?应该怎样做?Error 3 Only assignment, call, increment, decrement, and new object expressions can be used as a statement

解决方案 »

  1.   

    "int(" + dsDest.Tables[0].Rows[i][5].ToString() + ")"; 
    你倒底想让它存什么值呢。
      

  2.   

    switch (Int32.Parse(dgvDestTbl.Rows[1].Cells[1].Value.ToString())) 
    你看看你的判断。永远是找的第一行第一列的,然后给值的时候又给的不同行不同列。
    看不明白想做什么!
      

  3.   

    如果你是想绑定grid的话不是这么做。你最好百度一下grid绑定的相关资料,或者去官网直接查。
      

  4.   

    还有,如果dsDest是grid的话,你这样就算绑成功了基本上也不会显示的!
      

  5.   

    不好意思,我的代码应该是下面这样,我的目的是更改Datagridview的单元格值。            for (int i = 0; i < dsDest.Tables[0].Rows.Count - 1; i++)
                {
                    switch (Int32.Parse(dgvDestTbl.Rows[i].Cells[1].Value.ToString()))
                    {
                        case 56:
                            dgvDestTbl.Rows[i].Cells[1].Value == "int(" + dsDest.Tables[0].Rows[i][5].ToString() + ")";
                            break;
                        case 61:
                            dgvDestTbl.Rows[i].Cells[1].Value == "datetime";
                            break;
                        case 231:
                            dgvDestTbl.Rows[i].Cells[1].Value == "nvarchar(" + dsDest.Tables[0].Rows[i][5].ToString() + ")";
                            break;
                        case 167:
                            dgvDestTbl.Rows[i].Cells[1].Value == "varchar(" + dsDest.Tables[0].Rows[i][5].ToString() + ")";
                            break;
                        case 52:
                            dgvDestTbl.Rows[i].Cells[1].Value == "smallint(" + dsDest.Tables[0].Rows[i][5].ToString() + ")";
                            break;
                        case 108:
                            dgvDestTbl.Rows[i].Cells[1].Value == "numeric(" + dsDest.Tables[0].Rows[i][5].ToString() + ")";
                            break;
                    }
                }
      

  6.   


                    switch (Int32.Parse(dgvDestTbl.Rows[1].Cells[1].Value.ToString())) 
                    { 
                        case 56: 
                            dgvDestTbl.Rows[i].Cells[1].Value == Convert.ToInt32(dsDest.Tables[0].Rows[i][5].ToString());
                            break; 
                        case 61: 
                            dgvDestTbl.Rows[i].Cells[1].Value == Convert.ToDateTime("2008-7-25");
                            break; 
                        case 231: 
                            dgvDestTbl.Rows[i].Cells[1].Value == dsDest.Tables[0].Rows[i][5].ToString();
                            break; 
                        case 167: 
                            dgvDestTbl.Rows[i].Cells[1].Value == dsDest.Tables[0].Rows[i][5].ToString(); 
                            break; 
                        case 52: 
                            dgvDestTbl.Rows[i].Cells[1].Value == dsDest.Tables[0].Rows[i][5].ToString(); 
                            break; 
                        case 108: 
                            dgvDestTbl.Rows[i].Cells[1].Value == dsDest.Tables[0].Rows[i][5].ToString(); 
                            break; 
                    } 
      

  7.   

    你要修改的与你要判断的是同一个单元格,而判断条件必须为INT类型(从你的case段可以看出),当你修改为字符时,这个判断就会出错,知道么。
      

  8.   

     //编辑
        protected void GridView_UserManage_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView_UserManage.EditIndex = e.NewEditIndex;
            GridView_UserManage_DataBind();
        }
    //更新
        protected void GridView_UserManage_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            string pwd = ((TextBox)(GridView_UserManage.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim();
            if (pwd.Length < 16||pwd.Length==0)
            {
                Response.Write("<script language=javascript>confirm('你确定要修改该员工的密码吗?')</script>");
                int id = Convert.ToInt32(GridView_UserManage.DataKeys[e.RowIndex].Value);
                pwd = cc.Md5Pass(pwd);
                string sql = "update Oper_users set Oper_pwd='" + pwd + "' where Oper_id='" + id + "'";
                co.ENonQuery(sql);
            }    
            GridView_UserManage.EditIndex = -1;
            GridView_UserManage_DataBind();
        }
    <asp:GridView ID="GridView_UserManage" runat="server" AllowPaging="True" AllowSorting="True"
                                                                                    AutoGenerateColumns="False" BorderColor="#006699" BorderStyle="Solid" BorderWidth="1px"
                                                                                    CellPadding="4" DataKeyNames="Oper_id" ForeColor="#333333" GridLines="Vertical" OnPageIndexChanging="GridView_UserManage_PageIndexChanging"
                                                                                    OnRowCancelingEdit="GridView_UserManage_RowCancelingEdit" OnRowDataBound="GridView_UserManage_RowDataBound"
                                                                                    OnRowDeleting="GridView_UserManage_RowDeleting" OnRowEditing="GridView_UserManage_RowEditing"
                                                                                    OnRowUpdating="GridView_UserManage_RowUpdating" OnSorting="GridView_UserManage_Sorting" Width="100%" Font-Size="14px">
                                                                                    <Columns>
                                                                                        <asp:TemplateField>
                                                                                            <ItemTemplate>
                                                                                                <asp:CheckBox ID="check" runat="server" />
                                                                                            </ItemTemplate>
                                                                                        </asp:TemplateField>
                                                                                        <asp:BoundField DataField="Oper_code" HeaderText="工号" ReadOnly="True" />
                                                                                        <asp:BoundField DataField="Oper_name" HeaderText="员工姓名" ReadOnly="True" />
                                                                                        <asp:BoundField DataField="Depart_name" HeaderText="所属部门" ReadOnly="True" />
                                                                                        <asp:BoundField DataField="Oper_pwd" HeaderText="用户密码" />//要编辑的地方不要设置ReadOnly="True"
                                                                                        <asp:CommandField HeaderText="编辑" ShowEditButton="True" />
                                                                                        <asp:CommandField HeaderText="删除" ShowDeleteButton="True" />
                                                                                    </Columns>
                                                                                    <RowStyle ForeColor="#000066" />
                                                                                    <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="#006699" HorizontalAlign="Center"
                                                                                        VerticalAlign="Middle" />
                                                                                    <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
                                                                                    <PagerStyle BackColor="White" ForeColor="#000066" Height="16px" HorizontalAlign="Left"
                                                                                        VerticalAlign="Middle" />
                                                                                    <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" Height="18px" HorizontalAlign="Center" />
                                                                                    <AlternatingRowStyle BackColor="LightSteelBlue" />
                                                                                </asp:GridView>