下拉列表重复值 [英] drop down list duplicate values
本文介绍了下拉列表重复值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请我急需帮助
i搞砸了我的下拉列表
i有gride视图,其中数据表带有文本框和下拉列表,当我选择值时在ddl中并在文本框中写入文本单击添加行它保留文本框值并松散所选项目值
首先从数据库加载数据超过1次
秒我无法捕获所选索引我的代码我在我的Page_Load sub中没有写任何内容
please i need urget help
i am messed up with my drop down list
i have gride view in which data table with text boxes and drop down list when i choose value in ddl and write text in text boxes the click add row it preserve the text box values and loose selected item value
first the data is loaded from database more than 1 time
second i can not capture the selected index my code i wrote nothing in my Page_Load sub
Private Function GetData(ByVal query As String) As DataSet
da = clnconn.MyDataAdapterclnc(query)
da.Fill(ds)
Return ds
End Function
Protected Sub OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If (e.Row.RowType = DataControlRowType.DataRow) Then
'Find the DropDownList in the Row
Dim dropjobqs As DropDownList = CType(e.Row.FindControl("dropjobqs"), DropDownList)
Try
dropjobqs.DataTextField = "JBNME"
dropjobqs.DataValueField = "JBCDE"
dropjobqs.DataSource = GetData("Select JBNME,JBCDE from JOBBSDB")
dropjobqs.DataBind()
'Add Default Item in the DropDownList
dropjobqs.Items.Insert(0, New ListItem("Please select"))
Catch ex As NullReferenceException
Response.Write("Processor Usage" + ex.Message)
'the error in start generated here
End Try
End If
' dr.Dispose()
End Sub
Private Sub AddNewRowToGrid()
Dim rowIndex As Integer = 0
If ViewState("CurrentTable") IsNot Nothing Then
Dim dtCurrentTable As DataTable = DirectCast(ViewState("CurrentTable"), DataTable)
Dim drCurrentRow As DataRow = Nothing
If dtCurrentTable.Rows.Count > 0 Then
For i As Integer = 1 To dtCurrentTable.Rows.Count
'extract the TextBox values
Dim dropjobqs As DropDownList = DirectCast(Gridview1.Rows(rowIndex).Cells(6).FindControl("dropjobqs"), DropDownList)
Dim box1 As TextBox = DirectCast(Gridview1.Rows(rowIndex).Cells(1).FindControl("empnum"), TextBox)
Dim box2 As TextBox = DirectCast(Gridview1.Rows(rowIndex).Cells(2).FindControl("empnme"), TextBox)
Dim box3 As TextBox = DirectCast(Gridview1.Rows(rowIndex).Cells(3).FindControl("brnch"), TextBox)
Dim chkdelete As CheckBox = DirectCast(Gridview1.Rows(rowIndex).Cells(4).FindControl("chkdelete"), CheckBox)
Dim chkdental As CheckBox = DirectCast(Gridview1.Rows(rowIndex).Cells(5).FindControl("chkdental"), CheckBox)
Dim box4 As TextBox = DirectCast(Gridview1.Rows(rowIndex).Cells(4).FindControl("tel"), TextBox)
Dim box5 As TextBox = DirectCast(Gridview1.Rows(rowIndex).Cells(5).FindControl("TextBox5"), TextBox)
drCurrentRow = dtCurrentTable.NewRow()
drCurrentRow("EBRNNME") = i + 1
dtCurrentTable.Rows(i - 1)("Column1") = box1.Text
dtCurrentTable.Rows(i - 1)("Column2") = box2.Text
dtCurrentTable.Rows(i - 1)("Column3") = box3.Text
dtCurrentTable.Rows(i - 1)("Column4") = box4.Text 'the value between brackets is where the value of checked box will be written
dtCurrentTable.Rows(i - 1)("Column5") = box5.Text 'the value between brackets is where the value of checked box will be written
dtCurrentTable.Rows(i - 1)("dropjobqs") = dropjobqs.SelectedItem
box3.Enabled = False
box5.Enabled = False
rowIndex += 1
Next
dtCurrentTable.Rows.Add(drCurrentRow)
ViewState("CurrentTable") = dtCurrentTable
Gridview1.DataSource = dtCurrentTable
Gridview1.DataBind()
End If
Else
Response.Write("ViewState is null")
End If
SetPreviousData()
End Sub
Private Sub SetPreviousData()
Dim rowIndex As Integer = 0
If ViewState("CurrentTable") IsNot Nothing Then
Dim dt As DataTable = DirectCast(ViewState("CurrentTable"), DataTable)
If dt.Rows.Count > 0 Then
For i As Integer = 0 To dt.Rows.Count - 1
Dim dropjobqs As DropDownList = DirectCast(Gridview1.Rows(rowIndex).Cells(6).FindControl("dropjobqs"), DropDownList)
Dim box1 As TextBox = DirectCast(Gridview1.Rows(rowIndex).Cells(1).FindControl("empnum"), TextBox)
Dim box2 As TextBox = DirectCast(Gridview1.Rows(rowIndex).Cells(2).FindControl("empnme"), TextBox)
Dim box3 As TextBox = DirectCast(Gridview1.Rows(rowIndex).Cells(3).FindControl("brnch"), TextBox)
Dim chkdelete As CheckBox = DirectCast(Gridview1.Rows(rowIndex).Cells(4).FindControl("chkdelete"), CheckBox)
Dim chkdental As CheckBox = DirectCast(Gridview1.Rows(rowIndex).Cells(5).FindControl("chkdental"), CheckBox)
Dim box4 As TextBox = DirectCast(Gridview1.Rows(rowIndex).Cells(4).FindControl("tel"), TextBox)
Dim box5 As TextBox = DirectCast(Gridview1.Rows(rowIndex).Cells(5).FindControl("TextBox5"), TextBox)
' box5.Visible = True
box3.Enabled = False
'box4.Visible = True
' box5.Enabled = False
box1.Text = dt.Rows(i)("Column1").ToString()
box3.Text = dt.Rows(i)("Column3").ToString()
box2.Text = dt.Rows(i)("Column2").ToString()
box4.Text = dt.Rows(i)("Column4").ToString() 'write the value of checked box in box4
box5.Text = dt.Rows(i)("Column5").ToString()
dropjobqs.SelectedIndex = ViewState(dropjobqs.UniqueID) Is Nothing
chkdelete.Checked = ViewState(chkdelete.UniqueID) IsNot Nothing
chkdental.Checked = ViewState(chkdental.UniqueID) IsNot Nothing
'the coming lines to make the checkbox uneditable if checked
If ViewState(dropjobqs.UniqueID) IsNot Nothing Then
dropjobqs.SelectedValue = ViewState(dropjobqs.UniqueID)
End If
'If ViewState(chkdental.UniqueID) IsNot Nothing Then
'chkdental.Enabled = False
'End If
rowIndex += 1
Next
End If
End If
End Sub
Protected Sub dropjobq_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim row As GridViewRow = DirectCast(DirectCast(sender, DropDownList).NamingContainer, GridViewRow)
Dim index As Integer = row.RowIndex
Dim dt As DataTable = DirectCast(ViewState("CurrentTable"), DataTable)
Dim rowIndex As Integer = 0
If dt.Rows.Count > 0 Then
For i As Integer = 0 To dt.Rows.Count - 1
Dim dropjobqs As DropDownList = DirectCast(Gridview1.Rows(index).FindControl("dropjobqs"), DropDownList)
If dropjobqs.SelectedIndex Then
ViewState(dropjobqs.UniqueID) = dropjobqs.SelectedIndex
Else
ViewState.Remove(dropjobqs.UniqueID)
End If
' If dropjobqs.SelectedIndex Then
'ViewState(dropjobqs.UniqueID) = dropjobqs.SelectedIndex
'ViewState.Remove(dropjobqs.UniqueID)
' End If
rowIndex += 1
dropjobqs.DataSource = dr
dropjobqs.DataBind()
Next
End If
End Sub
请紧急
推荐答案
使用:
Use:
dropjobqs.DataSource = GetData("Select DISTINCT JBNME,JBCDE from JOBBSDB")
更多关于: SELECT DISTINCT(T-SQL) [ ^ ]
这篇关于下拉列表重复值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文