 |
|
โค้ดการแสดงข้อความใน label เมื่อทำการคลิกเลือก Drop-Down List ค่ะ |
|
 |
|
|
 |
 |
|
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
ลองดู ครับ
|
 |
 |
 |
 |
Date :
2012-04-03 08:16:08 |
By :
Thep |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
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
ของที่ทำ ขึ้นมาแต่ข้อความไม่แสดงบน label
|
 |
 |
 |
 |
Date :
2012-04-03 11:07:15 |
By :
habeeb |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่วยดูให้ หน่อยน่ะค่ะ
|
 |
 |
 |
 |
Date :
2012-04-03 11:16:33 |
By :
habeeb |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
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
1. Me.ddlTypeBr คือ อะไร?
2. ลองใส่ else ดูว่าขึ้นไหม?
3. ถ้า ใส่ else แล้วขึ้น แสดงว่า Me.ddlTypeBr ไม่ได้ส่งค่า 1 หรือ 2 เข้ามา
ลองดูครับ
|
 |
 |
 |
 |
Date :
2012-04-03 13:07:49 |
By :
Thep |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Me.ddlTypeBr คือ แทนประเภทของหน่วยงาน เช่น ฝ่าย กับ สาขา โดยใช้ เรียกค่าใน Drop-Down List ค่ะ
ลองใส่ else แล้วไม่ขึ้น ไม่แน่ใจว่า err อะไร ค่ะ
การส่งค่า Me.ddlTypeBr ส่งค่า 1 หรือ 2 โดยแทนค่า 1 = ฝ่าย , 2 = สาขา
โค้ดที่ทำยุตอนนี้ค่ะ ลองดูให้อีกครั้งน่ะค่ะ
Code (VB.NET)
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
ประมารนี้ค่ะ พีลองดูให้บีอีกครั้งน่ะค่ะ
|
 |
 |
 |
 |
Date :
2012-04-03 13:44:59 |
By :
habeeb |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ส่วนโค้ดด้านล่างนี้ใช้ เป็นอีกหนึ่งตัวอย่าง ค่ะ
Code (VB.NET)
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 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
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 Sub
เปลี่ยนจาก Me.ddlTypeBr.SelectedValue มาเป็น Me.ddlTypeBr.SelectedItem ครับ
ลองดูครับ
|
 |
 |
 |
 |
Date :
2012-04-03 14:34:32 |
By :
Thep |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเปลี่ยน Me.ddlTypeBr.SelectedValue มาเป็น Me.ddlTypeBr.SelectedItem แล้วค่ะ
ผลออกมา err ตรง If Me.ddlTypeBr.SelectedItem = "1" Then ค่ะ
|
 |
 |
 |
 |
Date :
2012-04-03 14:43:03 |
By :
habeeb |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
1. เพิ่ม Javascript
<script language="javascript">
function fncChange(_val){
if (_val=="1"){
document.getElementById("span1").innerHTML = "ฝ่าย";
}
else{
document.getElementById("span1").innerHTML = "สาขา";
}
}
</script>
2. เพิ่ม AutoPostBack="false" onChange="javascript:fncChange(ddlTypeBr.value)" ที่ ddlBranch
<asp:DropDownList ID="ddlBranch" runat="server" AutoPostBack="false" onChange="javascript:fncChange(ddlTypeBr.value)">
</asp:DropDownList>
3. เปลี่ยน lbBr.Text เป็น <span id="span1">span</span>
ลองดู ครับ
|
 |
 |
 |
 |
Date :
2012-04-03 15:28:34 |
By :
Thep |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สาม ส่วนที่พี่ให้เพิ่มเข้าไป เพิ่มในส่วนไหนบ้างค่ะ งงไปหมดแล้ว
น้อง ลองเพิ่มดู แล้วแต่ยัง ยัง err อยู่ค่ะ พี่ช่วยยกตัวอย่างให้หน่อยน่ะค่ะ
Code (VB.NET)
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="User.aspx.vb" Inherits="User" %>
<%@ Register src="UserControl/WebHeader.ascx" tagname="WebHeader" tagprefix="uc1" %>
<%@ Register assembly="eWorld.UI" namespace="eWorld.UI" tagprefix="ew" %>
<%--<%@ Register assembly="eWorld.UI" namespace="eWorld.UI" tagprefix="ew" %>--%>
<%@ Register assembly="System.Web.DynamicData, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.DynamicData" tagprefix="cc1" %>
<!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">
</head>
<style type="text/css">
.style1
{
width: 116%;
}
.style2
{
text-align: left;
font-family: Tahoma;
font-size: medium;
}
.newStyle1
{
}
.style9
{
width: 315px;
}
.style11
{
height: 27px;
width: 315px;
}
.style12
{
width: 154px;
text-align: right;
}
.style13
{
height: 26px;
width: 154px;
text-align: right;
}
.style14
{
height: 27px;
width: 154px;
text-align: right;
}
.style23
{
text-align: left;
}
.style26
{
width: 315px;
height: 26px;
}
.style27
{
text-align: left;
width: 141px;
}
</style>
<body>
<form id="form1" runat="server">
<div>
<uc1:WebHeader ID="WebHeader1" runat="server" />
</div>
<title></title>
<table>
<tr>
<td class="style12">
</td>
<td class="style9">
</td>
</tr>
<tr>
<td class="style12">
ชื่อ-สกุล : </td>
<td colspan=3>
<table>
<tr>
<td class="style23">
<asp:TextBox ID="txtName" runat="server" Width="164px"></asp:TextBox>
<br />
</td>
<td class="style27">
<asp:TextBox ID="txtLastName" runat="server" Width="141px"></asp:TextBox>
<br />
</td>
</tr>
</table>
<tr>
<td class="style13">
E-Mail :<br />
</td>
<td class="style26">
<asp:TextBox ID="txtEmail" runat="server" Height="22px" Width="264px"
style="margin-left: 3px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style14">
เบอร์โทร :</td>
<td class="style11">
<asp:TextBox ID="txtTel" runat="server" Width="262px" style="margin-left: 3px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style13">
ประเภทหน่วยงาน:</td>
<td class="style9">
<asp:DropDownList ID="ddlTypeBr" runat="server" Height="19px" Width="150px">
<asp:ListItem>== กรุณาเลือก ==</asp:ListItem>
<asp:ListItem Value="1">ฝ่าย</asp:ListItem>
<asp:ListItem Value="2">สาขา</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style13">
<asp:Label ID="lbBr" runat="server" EnableTheming="True"></asp:Label>
:</td>
<td class="style9">
<asp:DropDownList ID="ddlBranch" runat="server" Height="21px"
Width="150px" style="margin-left: 0px; margin-bottom: 0px"
DataTextField="detail" DataValueField="id">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style13">
ตำแหน่ง :</td>
<td class="style9">
<asp:DropDownList ID="ddlPosition" runat="server" Height="17px"
Width="170px" style="margin-left: 0px; margin-bottom: 0px"
DataTextField="detail" DataValueField="id">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style12">
วันที่สร้าง :
</td>
<td class="style9">
<ew:CalendarPopup ID="cldCreatDate" runat="server" ControlDisplay="TextBoxImage"
ImageUrl="~/Images/calendar.gif">
</ew:CalendarPopup>
</td>
</tr>
<tr>
<td class="style12">
วันที่แก้ไข :
</td>
<td class="style9">
<ew:CalendarPopup ID="cldEditDate" runat="server" ControlDisplay="TextBoxImage"
ImageUrl="~/Images/calendar.gif">
</ew:CalendarPopup>
</td>
</tr>
<tr>
<td class="style14">
ระดับการใช้งานระบบ :</td>
<td class="style11">
<asp:DropDownList ID="ddlLevel" runat="server" Height="16px"
Width="159px" style="margin-left: 0px; margin-bottom: 0px"
DataTextField="detail" DataValueField="id">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<td class="style12">
<td>
</td>
</td>
<tr>
<td class="style13">
</td>
<td class="style9">
<asp:Button ID="btnSave" runat="server" Text="บันทึก" Width="84px" />
<asp:Button ID="btnCancel" runat="server" Text="ยกเลิก" Width="86px" />
</td>
</tr>
</table>
</form>
</body>
</html>
|
 |
 |
 |
 |
Date :
2012-04-03 16:03:32 |
By :
habeeb |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="User.aspx.vb" Inherits="User" %>
<%@ Register src="UserControl/WebHeader.ascx" tagname="WebHeader" tagprefix="uc1" %>
<%@ Register assembly="eWorld.UI" namespace="eWorld.UI" tagprefix="ew" %>
<%--<%@ Register assembly="eWorld.UI" namespace="eWorld.UI" tagprefix="ew" %>--%>
<%@ Register assembly="System.Web.DynamicData, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.DynamicData" tagprefix="cc1" %>
<!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 = "ฝ่าย";
}
else if(_val=="2"){
document.getElementById("lbBr").innerHTML = "สาขา";
}
else{
document.getElementById("lbBr").innerHTML = "";
}
}
</script>
</head>
<style type="text/css">
.style1
{
width: 116%;
}
.style2
{
text-align: left;
font-family: Tahoma;
font-size: medium;
}
.newStyle1
{
}
.style9
{
width: 315px;
}
.style11
{
height: 27px;
width: 315px;
}
.style12
{
width: 154px;
text-align: right;
}
.style13
{
height: 26px;
width: 154px;
text-align: right;
}
.style14
{
height: 27px;
width: 154px;
text-align: right;
}
.style23
{
text-align: left;
}
.style26
{
width: 315px;
height: 26px;
}
.style27
{
text-align: left;
width: 141px;
}
</style>
<body>
<form id="form1" runat="server">
<div>
<uc1:WebHeader ID="WebHeader1" runat="server" />
</div>
<title></title>
<table>
<tr>
<td class="style12">
</td>
<td class="style9">
</td>
</tr>
<tr>
<td class="style12">
ชื่อ-สกุล : </td>
<td colspan=3>
<table>
<tr>
<td class="style23">
<asp:TextBox ID="txtName" runat="server" Width="164px"></asp:TextBox>
<br />
</td>
<td class="style27">
<asp:TextBox ID="txtLastName" runat="server" Width="141px"></asp:TextBox>
<br />
</td>
</tr>
</table>
<tr>
<td class="style13">
E-Mail :<br />
</td>
<td class="style26">
<asp:TextBox ID="txtEmail" runat="server" Height="22px" Width="264px"
style="margin-left: 3px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style14">
เบอร์โทร :</td>
<td class="style11">
<asp:TextBox ID="txtTel" runat="server" Width="262px" style="margin-left: 3px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style13">
ประเภทหน่วยงาน:</td>
<td class="style9">
<asp:DropDownList ID="ddlTypeBr" runat="server" Height="19px" Width="150px">
<asp:ListItem>== กรุณาเลือก ==</asp:ListItem>
<asp:ListItem Value="1">ฝ่าย</asp:ListItem>
<asp:ListItem Value="2">สาขา</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style13">
<span id="lbBr"></span>
:</td>
<td class="style9">
<asp:DropDownList ID="ddlBranch" runat="server" Height="21px"
Width="150px" style="margin-left: 0px; margin-bottom: 0px"
DataTextField="detail" DataValueField="id" AutoPostBack="false"
onChange="javascript:fncChange(ddlTypeBr.value)">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style13">
ตำแหน่ง :</td>
<td class="style9">
<asp:DropDownList ID="ddlPosition" runat="server" Height="17px"
Width="170px" style="margin-left: 0px; margin-bottom: 0px"
DataTextField="detail" DataValueField="id">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style12">
วันที่สร้าง :
</td>
<td class="style9">
<ew:CalendarPopup ID="cldCreatDate" runat="server" ControlDisplay="TextBoxImage"
ImageUrl="~/Images/calendar.gif">
</ew:CalendarPopup>
</td>
</tr>
<tr>
<td class="style12">
วันที่แก้ไข :
</td>
<td class="style9">
<ew:CalendarPopup ID="cldEditDate" runat="server" ControlDisplay="TextBoxImage"
ImageUrl="~/Images/calendar.gif">
</ew:CalendarPopup>
</td>
</tr>
<tr>
<td class="style14">
ระดับการใช้งานระบบ :</td>
<td class="style11">
<asp:DropDownList ID="ddlLevel" runat="server" Height="16px"
Width="159px" style="margin-left: 0px; margin-bottom: 0px"
DataTextField="detail" DataValueField="id">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<td class="style12">
<td>
</td>
</td>
<tr>
<td class="style13">
</td>
<td class="style9">
<asp:Button ID="btnSave" runat="server" Text="บันทึก" Width="84px" />
<asp:Button ID="btnCancel" runat="server" Text="ยกเลิก" Width="86px" />
</td>
</tr>
</table>
</form>
</body>
</html>
Copy ทั้งหมด เอาไปแทนของเดิม อย่าลืม BackUp ของเก่าก่อน นะค่ัะ
|
 |
 |
 |
 |
Date :
2012-04-03 16:23:59 |
By :
Thep |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พี่ ค่ะ err
Source Error:
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 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
'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
เอา Comment ไปก่อน ครับ
|
 |
 |
 |
 |
Date :
2012-04-03 16:55:23 |
By :
Thep |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไฟล์รูป ผลการรัน

ซึ่ง ผลที่ออกมา เมื่อคลิก ที่Drop-Down List สมมติ คลิกคำว่า ฝ่าย
ผลไม่แสดง ที่ label แต่ต้อง คลิก Drop-Down List ที่ ชื่อของฝ่ายก่อน มันถึง ขึ้น คำว่า ฝ่าย
แต่ที่ต้องการ
ต้องการให้ คลิกDrop-Down List คำว่าฝ่ายปัป ต้องการให้มันขึ้น คำว่า ฝ่าย ที่ label
|
 |
 |
 |
 |
Date :
2012-04-03 17:36:44 |
By :
habeeb |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<tr>
<td class="style13">
ประเภทหน่วยงาน:</td>
<td class="style9">
<asp:DropDownList ID="ddlTypeBr" runat="server" Height="19px" Width="150px" AutoPostBack="false"
onChange="javascript:fncChange(this.value)">
<asp:ListItem>== กรุณาเลือก ==</asp:ListItem>
<asp:ListItem Value="1">ฝ่าย</asp:ListItem>
<asp:ListItem Value="2">สาขา</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style13">
<span id="lbBr"></span>
:</td>
<td class="style9">
<asp:DropDownList ID="ddlBranch" runat="server" Height="21px"
Width="150px" style="margin-left: 0px; margin-bottom: 0px"
DataTextField="detail" DataValueField="id">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
เอา Code ตรงส่วนนี้ไป ทับเฉพาะตรงส่วนนี้ของ อันเดิม
|
 |
 |
 |
 |
Date :
2012-04-03 18:00:26 |
By :
Thep |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากค่ะ ใช้ได้แล้ว
แต่ตอนนี้ ยังเหลือ ตรงที่ว่า
ได้แล้ว
1. เมื่อทำการเลือกคำว่า ฝ่าย จาก Drop-Down List ก็จะขึ้นคำว่าฝ่าย label ส่วนนี้ ได้แล้วค่ะ
ต้องการประมาณนี้ค่ะ
2. เมื่อเลือกฝ่าย แล้วก็ขึ้น คำว่าฝ่าย เสด หลังจากนั่น อยากให้ Drop-Down List ขึ้นเฉพาะชื่อฝ่ายเท่านั่น เช่นเดี่ยวกัน เมื่อเลือก สาขา ก็อยากให้ขึ้นเฉพาะ ชื่อสาขา เช่นกันค่ะ
***อย่างเช่น ภาพของฟอร์มด้านบน เมื่อเลือกฝ่ายก็จะ ชื่อ ของสาขา เช่น ฝ่าย แล้วก็ขึ้นว่า นนทบุรี ซึ่งจากพอร์มนี้ผลยังผิด อยู่ค่ะ
|
 |
 |
 |
 |
Date :
2012-04-04 10:07:47 |
By :
habeeb |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พี่ค่ะ ช่วยด้วย ^^
|
 |
 |
 |
 |
Date :
2012-04-04 10:31:08 |
By :
habeeb |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="User.aspx.vb" Inherits="User" %>
<%@ Register src="UserControl/WebHeader.ascx" tagname="WebHeader" tagprefix="uc1" %>
<%@ Register assembly="eWorld.UI" namespace="eWorld.UI" tagprefix="ew" %>
<%--<%@ Register assembly="eWorld.UI" namespace="eWorld.UI" tagprefix="ew" %>--%>
<%@ Register assembly="System.Web.DynamicData, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.DynamicData" tagprefix="cc1" %>
<!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);
}
}
</script>
</head>
<style type="text/css">
.style1
{
width: 116%;
}
.style2
{
text-align: left;
font-family: Tahoma;
font-size: medium;
}
.newStyle1
{
}
.style9
{
width: 315px;
}
.style11
{
height: 27px;
width: 315px;
}
.style12
{
width: 154px;
text-align: right;
}
.style13
{
height: 26px;
width: 154px;
text-align: right;
}
.style14
{
height: 27px;
width: 154px;
text-align: right;
}
.style23
{
text-align: left;
}
.style26
{
width: 315px;
height: 26px;
}
.style27
{
text-align: left;
width: 141px;
}
</style>
<body>
<form id="form1" runat="server">
<div>
<uc1:WebHeader ID="WebHeader1" runat="server" />
</div>
<title></title>
<table>
<tr>
<td class="style12">
</td>
<td class="style9">
</td>
</tr>
<tr>
<td class="style12">
ชื่อ-สกุล : </td>
<td colspan=3>
<table>
<tr>
<td class="style23">
<asp:TextBox ID="txtName" runat="server" Width="164px"></asp:TextBox>
<br />
</td>
<td class="style27">
<asp:TextBox ID="txtLastName" runat="server" Width="141px"></asp:TextBox>
<br />
</td>
</tr>
</table>
<tr>
<td class="style13">
E-Mail :<br />
</td>
<td class="style26">
<asp:TextBox ID="txtEmail" runat="server" Height="22px" Width="264px"
style="margin-left: 3px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style14">
เบอร์โทร :</td>
<td class="style11">
<asp:TextBox ID="txtTel" runat="server" Width="262px" style="margin-left: 3px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style13">
ประเภทหน่วยงาน:</td>
<td class="style9">
<asp:DropDownList ID="ddlTypeBr" runat="server" Height="19px" Width="150px" AutoPostBack="false"
onChange="javascript:fncChange(this.value)">
<asp:ListItem>== กรุณาเลือก ==</asp:ListItem>
<asp:ListItem Value="1">ฝ่าย</asp:ListItem>
<asp:ListItem Value="2">สาขา</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style13">
<span id="lbBr"></span>
:</td>
<td class="style9">
<select name="ddlBranch" id="ddlBranch">
<option value="">== กรุณาเลือก ==</option>
</select>
<%--<asp:DropDownList ID="ddlBranch" runat="server" Height="21px"
Width="150px" style="margin-left: 0px; margin-bottom: 0px"
DataTextField="detail" DataValueField="id">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>--%>
</td>
</tr>
<tr>
<td class="style13">
ตำแหน่ง :</td>
<td class="style9">
<asp:DropDownList ID="ddlPosition" runat="server" Height="17px"
Width="170px" style="margin-left: 0px; margin-bottom: 0px"
DataTextField="detail" DataValueField="id">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style12">
วันที่สร้าง :
</td>
<td class="style9">
<ew:CalendarPopup ID="cldCreatDate" runat="server" ControlDisplay="TextBoxImage"
ImageUrl="~/Images/calendar.gif">
</ew:CalendarPopup>
</td>
</tr>
<tr>
<td class="style12">
วันที่แก้ไข :
</td>
<td class="style9">
<ew:CalendarPopup ID="cldEditDate" runat="server" ControlDisplay="TextBoxImage"
ImageUrl="~/Images/calendar.gif">
</ew:CalendarPopup>
</td>
</tr>
<tr>
<td class="style14">
ระดับการใช้งานระบบ :</td>
<td class="style11">
<asp:DropDownList ID="ddlLevel" runat="server" Height="16px"
Width="159px" style="margin-left: 0px; margin-bottom: 0px"
DataTextField="detail" DataValueField="id">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<td class="style12">
<td>
</td>
</td>
<tr>
<td class="style13">
</td>
<td class="style9">
<asp:Button ID="btnSave" runat="server" Text="บันทึก" Width="84px" />
<asp:Button ID="btnCancel" runat="server" Text="ยกเลิก" Width="86px" />
</td>
</tr>
</table>
<input type="hidden" name="branch" id="branch" value="<%=branch%>">
<input type="hidden" name="department" id="department" value="<%=department%>">
</form>
</body>
</html>
*********** Copy Code ด้านบน นี้ไปวางทับของเดิม (BackUp ก่อนด้วยนะครับ)
*************** ในส่วนของ 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()
' End ตัวอย่าง
end sub
หมายเหตุ : ข้อ 2 คือ เธอต้อง select ข้อมูล สาขามาเก็บไว้ที่ตัวแปร branch และ select ข้อมูล department มาเก็บไว้ที่ตัวแปร department โดยทั้ง 2 ตัวแปรต้องเก็บข้อมูลอย่างนี้ A,B,C มี Comma คั่นระหว่างข้อมูล
คือผมไม่รู้ว่า เธอ select ข้อมูลอย่างไงนะแต่ผลลัพธ์ ที่ได้ต้องอยู่ในรูปแบบ A,B,C มี Comma คั่นระหว่างข้อมูล ทั้ง 2 ตัวแปร branch และ department
3. ในส่วนของการ Save
เปลี่ยนจาก Trim(Me.ddlBranch.SelectedValue) มาเป็น Trim(request("ddlBranch")) แทน
|
 |
 |
 |
 |
Date :
2012-04-04 11:44:05 |
By :
Thep |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณพี่มากค่ะ จะลองดูน่ะค่ะ 
|
 |
 |
 |
 |
Date :
2012-04-04 11:54:31 |
By :
habeeb |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|