Replace data in gridview
-
Hello I have a field in my database with three options (unknown, yes, no) and the database stores numbers (1,2,3) I want to replace 1,2,3 with the corresponding unknown, yes or no in a bound datagrid. Any hints? Is it possible?
ma
tju
Pengaturcara Perisian Subang Jaya,Selangor, Malaysia Ring Master SB MVP 2008 ;p Subang Jaya MOP (Otai) -
Hello I have a field in my database with three options (unknown, yes, no) and the database stores numbers (1,2,3) I want to replace 1,2,3 with the corresponding unknown, yes or no in a bound datagrid. Any hints? Is it possible?
ma
tju
Pengaturcara Perisian Subang Jaya,Selangor, Malaysia Ring Master SB MVP 2008 ;p Subang Jaya MOP (Otai)hi after binding the datagrid run a for loop to change text of datagrid
-
hi after binding the datagrid run a for loop to change text of datagrid
-
Hello I have a field in my database with three options (unknown, yes, no) and the database stores numbers (1,2,3) I want to replace 1,2,3 with the corresponding unknown, yes or no in a bound datagrid. Any hints? Is it possible?
ma
tju
Pengaturcara Perisian Subang Jaya,Selangor, Malaysia Ring Master SB MVP 2008 ;p Subang Jaya MOP (Otai)first bind gridview with this field use loop for(int i=0; i0: i++) { // now find control where u bind this field value ex label l = (Label)(gridview1.rows[i].findControl("control_name")); string val = l.tostring(); if(val=="1") { l.Text=unknown; } else if(val=="2") { l.Text=yes; } else { l.Text=no; } }
-
Hello I have a field in my database with three options (unknown, yes, no) and the database stores numbers (1,2,3) I want to replace 1,2,3 with the corresponding unknown, yes or no in a bound datagrid. Any hints? Is it possible?
ma
tju
Pengaturcara Perisian Subang Jaya,Selangor, Malaysia Ring Master SB MVP 2008 ;p Subang Jaya MOP (Otai)Best way is to write in your SQL. Use Case[^] expression.
Navaneeth How to use google | Ask smart questions
-
first bind gridview with this field use loop for(int i=0; i0: i++) { // now find control where u bind this field value ex label l = (Label)(gridview1.rows[i].findControl("control_name")); string val = l.tostring(); if(val=="1") { l.Text=unknown; } else if(val=="2") { l.Text=yes; } else { l.Text=no; } }
Thanks sheha. I have already settle my problem. I insert this code in gridview_RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Or e.Row.RowType = DataControlRowType.Separator Then
Dim Idstr As String
Idstr = CType(e.Row.FindControl("lblId"), Label).Text
If Idstr = 1 Then
CType(e.Row.FindControl("lblId"), Label).Text = "Yes"
If Idstr = 2 Then
CType(e.Row.FindControl("lblId"), Label).Text = "No"
End If
End Ifma
tju
Pengaturcara Perisian Subang Jaya,Selangor, Malaysia Ring Master SB MVP 2008 ;p Subang Jaya MOP (Otai) -
Best way is to write in your SQL. Use Case[^] expression.
Navaneeth How to use google | Ask smart questions
Thanks navaneeth for your suggestion. I already find another way to solve my problem. Actually its hard for me to understand the article from msdn microsoft. :rolleyes:
ma
tju
Pengaturcara Perisian Subang Jaya,Selangor, Malaysia Ring Master SB MVP 2008 ;p Subang Jaya MOP (Otai) -
Hi, Where should i run the for loop. what should i read and replace. Thanks as an advanced
ma
tju
Pengaturcara Perisian Subang Jaya,Selangor, Malaysia Ring Master SB MVP 2008 ;p Subang Jaya MOP (Otai)after binding the datagrid If DataGrid1.Items.Count > 0 Then For i = 0 To DataGrid1.Items.Count - 1 if UCase(DataGrid1.Items(i).Cells(columnumber).Text) ="1" Then DataGrid1.Items(i).Cells(3).Text="Unknown" elseif UCase(DataGrid1.Items(i).Cells(columnumber).Text) ="2" Then DataGrid1.Items(i).Cells(3).Text="yes" elseif UCase(DataGrid1.Items(i).Cells(columnumber).Text) ="3" Then DataGrid1.Items(i).Cells(3).Text="no" End If Next End If