各位大侠,怎样将datagrid中一列的每个数据读出来处理后再将其写回到各自的位置?    如其中一行的dataSet3.Tables[0].Rows[0]["skzc"].ToString()的字符串为"001100",我已将其转换为"3-4",那么怎么再将其写回,或者写到该数据集的另一列也可以.
    所有行怎么处理?万分紧急!谢谢!!

解决方案 »

  1.   

    什么意思?你是想把dataset中的数据处理后再绑定到datagrid?
      

  2.   

    例如DataGrid为:
    Id Zc bm
    1 00111 0201
    2 11000 0202
      
      我如何将“zc”的值00111改为3-5后再写回?是否要增加模板列?
      

  3.   

    在DataBind之后:
    foreach(DataGridItem CurRow in 你的DataGrid.Items)
    {
    //CurRow.Cells[1].Text是第二列当前行里面的值,取出处理
              CurRow.Cells[1].Text=处理结果.ToString();
    }
      

  4.   

    OleDbCommandBuilder cb = new OleDbCommandBuilder(adp);
    adp.Update(dataSet3,"TableName");
      

  5.   

    Function Trans(ByVal str As String)
            Dim len As Int16 = str.Length
            Dim t() As Char
            Dim posB As String
            Dim posE As String
            Dim b As Boolean = False
            t = str.ToCharArray()
            Dim i As Integer
            For i = 0 To len - 1
                If t(i) = "1" Then
                    If b = False Then
                        posB = i + 1
                        b = True
                    End If
                    If i = len - 1 And posE = "" Then
                        posE = i + 1
                    End If
                Else
                    If posB <> "" Then
                        posE = i
                    End If
                End If
            Next
            Return posB + "-" + posE
        End Function
      

  6.   

    帮你写了一个转换函数你只需在Datagrid榜定之后 重新把每行判断一下 就可以在DataGrid  ItemDataBound事件中     (假定第2列为你要改变的列)
    写上就行
    if e.ItemType=ListItemType.Item then
         if e.Item.Cells(1).text<>"&nbsp;" then
              e.Item.Cells(1).text=Trans(e.Item.Cells(1).text)
          End if 
       
    End if