如果使用数据表“已经存在”,如何从gridview确定值

时间:2014-08-13 05:46:10

标签: vb.net

如何确定我的数据表中是否已存在

Protected Sub lnkSaveReference_Click(ByVal sender As Object, ByVal e As EventArgs)
 'Dim Button1 As Button = DirectCast(ifp_fv.FindControl("Button1"), Button)
 'If ViewState("CurrentDataReference").Equals("") Then
 'Button1.Visible = False
 'End If

 Dim ddlFg As DropDownList = DirectCast(ifp_fv.FindControl("select_fg"), DropDownList)
 If (Not (ViewState("CurrentDataReference")) Is Nothing) Then
   Dim dt As DataTable = CType(ViewState("CurrentDataReference"), DataTable)
   Dim count As Integer = dt.Rows.Count
   BindGridReference(count)
   ddlFg.SelectedValue = ""
 Else
   BindGridReference(1)
   ddlFg.SelectedValue = ""
 End If
End Sub

Private Sub BindGridReference(ByVal rowcount As Integer)
 Dim ddlFg As DropDownList = DirectCast(ifp_fv.FindControl("select_fg"), DropDownList)
 Dim gvFishingGround As GridView = DirectCast(ifp_fv.FindControl("gvFishingGround"), GridView)
 Dim Dt As DataTable = New DataTable
 Dim dr As DataRow
 Dt.Columns.Add(New System.Data.DataColumn("Fishing Ground", GetType(String)))

 For i = 0 To gvFishingGround.Rows.Count - 1
   dr = Dt.NewRow
 Next
 If (Not (ViewState("CurrentDataReference")) Is Nothing) Then
   Dim i As Integer = 0
   Do While (i < (rowcount + 1))
      Dt = CType(ViewState("CurrentDataReference"), DataTable)
      If (Dt.Rows.Count > 0) Then
        dr = Dt.NewRow
        dr(0) = Dt.Rows(0)(0).ToString
        dr(0) = Dt.Rows(0)(0).ToString
      End If
      i = (i + 1)
   Loop
   dr = Dt.NewRow
   dr(0) = ddlFg.SelectedItem.Text
   Dt.Rows.Add(dr)
  Else
   dr = Dt.NewRow
   dr(0) = ddlFg.SelectedItem.Text
   Dt.Rows.Add(dr)
  End If

  Dim select_fg As DropDownList = ifp_fv.FindControl("select_fg")
  Dim sfp_panel As Panel = ifp_fv.FindControl("sfp_panel")
  If dr(0) <> "High Seas Pocket 1" Then
    ifp_panel.Visible = True
  End If

  If dr(0) = "High Seas Pocket 1" Then
    sfp_panel.Visible = True
    ifp_panel.Visible = False
  Else
  End If

  Dim msg As Label = ifp_fv.FindControl("msg")
  If Dt.Columns.Contains("High Seas Pocket 1") Then
    msg.Text = "High Seas Pocket 1 Already Exist"
  End If

  If (Not (ViewState("CurrentDataReference")) Is Nothing) Then
                    gvFishingGround.DataSource = CType(ViewState("CurrentDataReference"), DataTable)
     gvFishingGround.DataBind()
     gvFishingGround.Focus()
  Else
     gvFishingGround.DataSource = Dt
     gvFishingGround.DataBind()
     gvFishingGround.Focus()
  End If
  ViewState("CurrentDataReference") = Dt
 End Sub

如果gridview数据表中已存在添加的下拉列表值,我将如何显示消息?????????????

这是我的消息代码块:

     Dim msg As Label = ifp_fv.FindControl("msg")
     If Dt.Columns.Contains("High Seas Pocket 1") Then
         msg.Text = "High Seas Pocket 1 Already Exist"
     End If

0 个答案:

没有答案