【发布时间】:2019-10-24 16:28:48
【问题描述】:
我有一个网格视图控件,其中包含从用户填写的表单填充的几列。在表单中,某些值不是强制性的,如果用户不选择它们,则显示为“选择”在网格视图中。当我加载网格视图时,如何将该值更改为“无”之类的相对值。换句话说,如果该列包含“选择”,则将其更改为“无”
这是我用来填充Gridview的代码
Private Sub LoadGridAll()
txtSearchEmployee.Text = ""
Try
Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("XXX").ConnectionString)
Using cmd As New SqlCommand("SELECT EmployeeCodes.Code, EmployeeCodes.FirstName , EmployeeCodes.LastName , EmployeeCodes.EmployeeID , CostCentre , ExaminationType.ExaminationTypeName , PhysicalExam.PhysicalExamName , ExaminationType.ExaminationTypeName , PhysicalExam.PhysicalExamName , Audiogram.AudiogramName , AudiogramRec.AudiogramRecName,LungFunction.LungFunctionName,ChestResults,ECGResult,DrugScreeningResult,BloodGlucoseResult,GGTResult,LeftEyeDayNight,RightEyeDayNight,LeftEyeCorrDayNight,RightEyeCorrDayNight,VisualFieldLeftDayNight,VisualFieldRightDayNight,ColourVisionDayNight,DeptPerceptionDayNight,OptometristYesNo,Outcome.Name , OutcomeRecommendations.OutcomeRecommendationsName,OtherProblems,Notes,DateTested,NextDueDate FROM MedicalResults,EmployeeCodes,ExaminationType,PhysicalExam,Audiogram,AudiogramRec,LungFunction,Outcome,OutcomeRecommendations WHERE MedicalResults.EmployeeID = EmployeeCodes.EmployeeID AND ExaminationType.ExaminationTypeID = MedicalResults.ExaminationTypeID AND PhysicalExam.PhysicalExamID = MedicalResults.PhysicalExamType AND Audiogram.AudiogramID = MedicalResults.AudiogramID AND MedicalResults.AudiogramRecID = AudiogramRec.AudiogramRecID AND LungFunction.LungFunctionID = MedicalResults.LungFunctionID AND OutcomeRecommendations.OutcomeRecommendationsID = MedicalResults.OutcomeRecommendationsID AND Outcome.OutcomeID = MedicalResults.OutcomeID ", conn)
conn.Open()
Dim sda As New SqlDataAdapter(cmd)
Dim dt As New DataTable()
sda.Fill(dt)
For Each row As DataRow In dt.Rows
Dim strDetail As Object
strDetail = row.Item(10)
If strDetail = "Select" Then
strDetail = "None"
End If
Next row
GridViewAll.DataSource = dt
GridViewAll.DataBind()
conn.Close()
End Using
End Using
Catch ex As Exception
End Try
End Sub
【问题讨论】: