การแสดงข้อความใน label โดยทำการคลิก Drop-Down List เพื่อต้องการเลือก แล้วเมื่อเลือก ข้อความที่เลือกจะขึ้นที่ label เช่น มีให้คลิก ฝ่ายกับสาขา คลิกเลือกฝ่าย ที่ Drop-Down List จะขึ้นคำว่าฝ่ายที่ label
Tag : .NET, Win (Windows App), VB.NET
Date :
2012-04-03 06:11:28
By :
bee
View :
4413
Reply :
19
No. 1
Guest
Code (VB.NET)
Private Sub ComboBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged
Me.lbl1.Text = Me.ComboBox3.SelectedItem
End Sub
Protected Sub ddlBranch_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlBranch.SelectedIndexChanged
If Me.ddlTypeBr.SelectedValue = "1" Then
Me.lbBr.Text = "ddlTypeBr"
ElseIf Me.ddlTypeBr.SelectedValue = "2" Then
Me.lbBr.Text = "ddlTypeBr"
End If
End Sub
Protected Sub ddlBranch_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlBranch.SelectedIndexChanged
If Me.ddlTypeBr.SelectedValue = "1" Then
Me.lbBr.Text = "ddlTypeBr"
ElseIf Me.ddlTypeBr.SelectedValue = "2" Then
Me.lbBr.Text = "ddlTypeBr"
else
Me.lbBr.Text = "Test"
End If
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
'FormTypeBr(Request.QueryString("LT"))
bindPosition()
bindBranch()
bindLevel()
End If
End Sub
Protected Sub bindPosition()
Dim sql As String
Dim dv As DataView
sql = "SELECT id,detail FROM tb_complaint_Position "
sql += " ORDER BY Sort_Id "
dv = ObjDb.GetDataSet(sql).Tables(0).DefaultView
If dv.Count > 0 Then
Me.ddlPosition.DataSource = dv
Me.ddlPosition.DataBind()
Me.ddlPosition.Items.Insert(0, "== กรุณาเลือก ==")
End If
End Sub
Protected Sub bindBranch()
Dim sql As String
Dim dv As DataView
sql = "SELECT id,detail FROM tb_complaint_branch "
dv = ObjDb.GetDataSet(sql).Tables(0).DefaultView
If dv.Count > 0 Then
Me.ddlBranch.DataSource = dv
Me.ddlBranch.DataBind()
Me.ddlBranch.Items.Insert(0, "== กรุณาเลือก ==")
End If
End Sub
Protected Sub bindLevel()
Dim sql As String
Dim dv As DataView
sql = "SELECT id,detail FROM tb_complaint_Level"
sql += " ORDER BY Sort_Id "
dv = ObjDb.GetDataSet(sql).Tables(0).DefaultView
If dv.Count > 0 Then
Me.ddlLevel.DataSource = dv
Me.ddlLevel.DataBind()
Me.ddlLevel.Items.Insert(0, "== กรุณาเลือก ==")
End If
End Sub
Protected Sub SaveData()
Dim sql As String
Dim Name As String
Dim LastName As String
Dim Email As String
Dim Tel As Integer
Dim ddlTypeBr As String
Dim ddlPosition As Integer
Dim ddlBranch As Integer
Dim CreatDate As String
Dim EditDate As String
Dim ddlLevel As String
Dim myReader As StreamReader
CreatDate = Format(cldCreatDate.SelectedDate.Date, "dd/MM/yyyy")
EditDate = Format(cldEditDate.SelectedDate.Date, "dd/MM/yyyy")
sql = "INSERT INTO tb_complaint_User(Name,Lastname,Email,Tel,TypeBr,Position,Branch,CreatDate,EditDate,Level)"
sql += " VALUES ('" & Trim(Me.txtName.Text) & "','" & Trim(Me.txtLastName.Text) & "','" & Trim(Me.txtEmail.Text) & "','" & Trim(Me.txtTel.Text) & "',"
sql += " '" & Trim(Me.ddlTypeBr.SelectedValue) & "','" & Trim(Me.ddlPosition.SelectedValue) & "','" & Trim(Me.ddlBranch.SelectedValue) & "','" & CreatDate & "','" & EditDate & "','" & Trim(Me.ddlLevel.SelectedValue) & "')"
Response.Write(sql)
ObjDb.ExecuteNonQuery(sql)
Page.ClientScript.RegisterStartupScript(Page.GetType(), "clientScript", "alert('บันทึกข้อมูลเรียบร้อย');", True)
End Sub
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
SaveData()
End Sub
Protected Sub ddlBranch_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlBranch.SelectedIndexChanged
If Me.ddlTypeBr.SelectedValue = "1" Then
Me.lbBr.Text = "ddlTypeBr"
ElseIf Me.ddlTypeBr.SelectedValue = "2" Then
Me.lbBr.Text = "ddlTypeBr"
else
Me.lbBr.Text = "Test"
End If
End Sub
Dim GetLetterType As String = Str()
Me.lb1.Text = GetLetterType
If GetLetterType = "1" Then
Me.lbLType.Text = "บันทึกรับ(ภายใน)"
Me.lbReceivedNo.Text = "เลขที่บันทึกรับ :"
Me.lbLetterDate.Text = "วันที่ในบันทึกรับ :"
ElseIf GetLetterType = "2" Then
Me.lbLType.Text = "หนังสือรับ(ภายนอก)"
Me.lbReceivedNo.Text = "เลขที่หนังสือรับ :"
Me.lbLetterDate.Text = "วันที่ในหนังสือรับ :"
ElseIf GetLetterType = "3" Then
Me.lbLType.Text = "บันทึกออก(ภายนอก)"
Me.lbReceivedNo.Text = "เลขที่บันทึกออก :"
Me.lbLetterDate.Text = "วันที่ในบันทึกออก :"
ElseIf GetLetterType = "4" Then
Me.lbLType.Text = "หนังสือออก(ภายนอก)"
Me.lbReceivedNo.Text = "เลขที่หนังสือออก :"
Me.lbLetterDate.Text = "วันที่ในหนังสือออก :"
End If
End Sub
ขอบคุณพี่ล่วงหน้ามากๆค่ะ ; )
Date :
2012-04-03 13:50:46
By :
habeeb
No. 7
Guest
Protected Sub ddlBranch_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlBranch.SelectedIndexChanged
If Me.ddlTypeBr.SelectedItem = "1" Then
Me.lbBr.Text = "ddlTypeBr"
ElseIf Me.ddlTypeBr.SelectedItem = "2" Then
Me.lbBr.Text = "ddlTypeBr"
else
Me.lbBr.Text = "Test"
End If
Line 91:
Line 92: Protected Sub ddlBranch_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlBranch.SelectedIndexChanged Line 93: If Me.ddlTypeBr.SelectedItem = "1" Then
Line 94: Me.lbBr.Text = "ddlTypeBr"
Line 95: ElseIf Me.ddlTypeBr.SelectedItem = "2" Then
Code (VB.NET)
Imports System.Data
Imports System.IO
Partial Class User
Inherits System.Web.UI.Page
Public ObjDb As New Datacenter.Data.clsDBSQLBased(ConfigurationManager.ConnectionStrings("ConStr").ToString)
Dim GetPath As String
Dim fFolder, fName, ServerPath As String
Private Property AssignDate As String
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
'If Session("IDUser") Is Nothing Or Session("IDUser") = "" Then
' Response.Redirect("Login.aspx")
'End If
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
'FormTypeBr(Request.QueryString("LT"))
bindPosition()
bindBranch()
bindLevel()
End If
End Sub
Protected Sub bindPosition()
Dim sql As String
Dim dv As DataView
sql = "SELECT id,detail FROM tb_complaint_Position "
sql += " ORDER BY Sort_Id "
dv = ObjDb.GetDataSet(sql).Tables(0).DefaultView
If dv.Count > 0 Then
Me.ddlPosition.DataSource = dv
Me.ddlPosition.DataBind()
Me.ddlPosition.Items.Insert(0, "== กรุณาเลือก ==")
End If
End Sub
Protected Sub bindBranch()
Dim sql As String
Dim dv As DataView
sql = "SELECT id,detail FROM tb_complaint_branch "
dv = ObjDb.GetDataSet(sql).Tables(0).DefaultView
If dv.Count > 0 Then
Me.ddlBranch.DataSource = dv
Me.ddlBranch.DataBind()
Me.ddlBranch.Items.Insert(0, "== กรุณาเลือก ==")
End If
End Sub
Protected Sub bindLevel()
Dim sql As String
Dim dv As DataView
sql = "SELECT id,detail FROM tb_complaint_Level"
sql += " ORDER BY Sort_Id "
dv = ObjDb.GetDataSet(sql).Tables(0).DefaultView
If dv.Count > 0 Then
Me.ddlLevel.DataSource = dv
Me.ddlLevel.DataBind()
Me.ddlLevel.Items.Insert(0, "== กรุณาเลือก ==")
End If
End Sub
Protected Sub SaveData()
Dim sql As String
Dim Name As String
Dim LastName As String
Dim Email As String
Dim Tel As Integer
Dim ddlTypeBr As String
Dim ddlPosition As Integer
Dim ddlBranch As Integer
Dim CreatDate As String
Dim EditDate As String
Dim ddlLevel As String
Dim myReader As StreamReader
CreatDate = Format(cldCreatDate.SelectedDate.Date, "dd/MM/yyyy")
EditDate = Format(cldEditDate.SelectedDate.Date, "dd/MM/yyyy")
sql = "INSERT INTO tb_complaint_User(Name,Lastname,Email,Tel,TypeBr,Position,Branch,CreatDate,EditDate,Level)"
sql += " VALUES ('" & Trim(Me.txtName.Text) & "','" & Trim(Me.txtLastName.Text) & "','" & Trim(Me.txtEmail.Text) & "','" & Trim(Me.txtTel.Text) & "',"
sql += " '" & Trim(Me.ddlTypeBr.SelectedValue) & "','" & Trim(Me.ddlPosition.SelectedValue) & "','" & Trim(Me.ddlBranch.SelectedValue) & "','" & CreatDate & "','" & EditDate & "','" & Trim(Me.ddlLevel.SelectedValue) & "')"
Response.Write(sql)
ObjDb.ExecuteNonQuery(sql)
Page.ClientScript.RegisterStartupScript(Page.GetType(), "clientScript", "alert('บันทึกข้อมูลเรียบร้อย');", True)
End Sub
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
SaveData()
End Sub
' err ตรงนี้อ่าค่ะ
[color=maroon] Protected Sub ddlBranch_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlBranch.SelectedIndexChanged
If Me.ddlTypeBr.SelectedItem = "1" Then
Me.lbBr.Text = "ddlTypeBr"
ElseIf Me.ddlTypeBr.SelectedItem = "2" Then
Me.lbBr.Text = "ddlTypeBr"
Else
Me.lbBr.Text = "Test"
End If
End SubEnd Class
Date :
2012-04-03 16:40:00
By :
habeeb
No. 13
Guest
'Protected Sub ddlBranch_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlBranch.SelectedIndexChanged
'If Me.ddlTypeBr.SelectedItem = "1" Then
'Me.lbBr.Text = "ddlTypeBr"
'ElseIf Me.ddlTypeBr.SelectedItem = "2" Then
'Me.lbBr.Text = "ddlTypeBr"
'Else
'Me.lbBr.Text = "Test"
'End If
'End SubEnd Class
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script language="javascript">
function fncChange(_val){
if (_val=="1"){
document.getElementById("lbBr").innerHTML = "ฝ่าย";
fncSelect(_val)
}
else if(_val=="2"){
document.getElementById("lbBr").innerHTML = "สาขา";
fncSelect(_val)
}
else{
document.getElementById("lbBr").innerHTML = "";
}
}
function fncSelect(_val){
var _Branch = "";
if(_val == "1"){
_Branch = document.getElementById ("branch").value.split(",")
}
else{
_Branch = document.getElementById ("department").value.split(",")
}
var newElem;
var _len = _Branch.length;
var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
var PChooser = document.form1.elements["ddlBranch"];
while (PChooser.options.length) {
PChooser.remove(0);
}
for (var i = 0; i < _len; i++) {
newElem = document.createElement("option");
newElem.text = _Branch[i];
newElem.value = _Branch[i];
PChooser.add(newElem, where);
}
*************** ในส่วนของ Code-Behind
1. สร้างตัวแปร 2 ตัว
Public branch, department As String
2. ในส่วนของ bindBranch()
Protected Sub bindBranch()
Dim sql As String
' ตัวอย่าง
Dim cmd As OleDbCommand
Dim reader As OleDbDataReader
sql = "SELECT id,detail FROM tb_complaint_branch " ' สาขา
cmd = New OleDbCommand(Sql, Conn)
reader = cmd.ExecuteReader
If reader.HasRows = True Then
While reader.Read
if branch <> "" then branch &=","
branch &= reader("detail")
End While
End If
reader.Close()
sql = "SELECT id,detail FROM tb_complaint_branch " ' ฝ่าย
cmd = New OleDbCommand(Sql, Conn)
reader = cmd.ExecuteReader
If reader.HasRows = True Then
While reader.Read
if department <> "" then department &=","
department &= reader("detail")
End While
End If
reader.Close()