在DataBind之后: foreach(DataGridItem CurRow in 你的DataGrid.Items) { //CurRow.Cells[1].Text是第二列当前行里面的值,取出处理 CurRow.Cells[1].Text=处理结果.ToString(); }
OleDbCommandBuilder cb = new OleDbCommandBuilder(adp); adp.Update(dataSet3,"TableName");
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
帮你写了一个转换函数你只需在Datagrid榜定之后 重新把每行判断一下 就可以在DataGrid ItemDataBound事件中 (假定第2列为你要改变的列) 写上就行 if e.ItemType=ListItemType.Item then if e.Item.Cells(1).text<>" " then e.Item.Cells(1).text=Trans(e.Item.Cells(1).text) End if
Id Zc bm
1 00111 0201
2 11000 0202
我如何将“zc”的值00111改为3-5后再写回?是否要增加模板列?
foreach(DataGridItem CurRow in 你的DataGrid.Items)
{
//CurRow.Cells[1].Text是第二列当前行里面的值,取出处理
CurRow.Cells[1].Text=处理结果.ToString();
}
adp.Update(dataSet3,"TableName");
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
写上就行
if e.ItemType=ListItemType.Item then
if e.Item.Cells(1).text<>" " then
e.Item.Cells(1).text=Trans(e.Item.Cells(1).text)
End if
End if