这样一个程序,该如何做成用户控件?
参数主要有三个:左右两个listbox和数据源
控件的值是右边listbox中的项。<body>
<form id="form1" runat="server">
<div>
<table style="width: 472px; height: 176px">
<tr>
<td rowspan="3" style="width: 100px">
<asp:ListBox ID="L_ListBox" runat="server" DataSourceID="SqlDataSource1" DataTextField="LastName"
DataValueField="LastName" Height="100px" Width="150px"></asp:ListBox><asp:SqlDataSource
ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString4 %>"
SelectCommand="SELECT [LastName] FROM [Employees]"></asp:SqlDataSource>
</td>
<td rowspan="3" style="width: 100px">
<table>
<tr>
<td style="width: 100px">
<asp:Button ID="Button1" runat="server" Text=">>" Width="50px" /></td>
</tr>
<tr>
<td style="width: 100px">
<asp:Button ID="Button2" runat="server" Text=">>>>" Width="50px" /></td>
</tr>
<tr>
<td style="width: 100px">
<asp:Button ID="Button3" runat="server" Text="<<" Width="50px" /></td>
</tr>
<tr>
<td style="width: 100px">
<asp:Button ID="Button4" runat="server" Text="<<<<" Width="50px" /></td>
</tr>
</table>
</td>
<td rowspan="3" style="width: 100px">
<asp:ListBox ID="R_ListBox" runat="server" Height="100px" Width="150px"></asp:ListBox></td>
</tr>
<tr>
</tr>
<tr>
</tr>
</table>
</div>
</form>
</body>
-------------以下是vb代码-----------------------------
Partial Class Default4
Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Protected Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i, n As Integer
i = 0
n = L_ListBox.Items.Count - 1
While i <= n
If L_ListBox.Items(i).Selected Then
R_ListBox.Items.Add(L_ListBox.Items(i))
L_ListBox.Items.Remove(L_ListBox.Items(i))
R_ListBox.Items(R_ListBox.Items.Count - 1).Selected = False
n = n - 1
Else
i = i + 1
End If
End While
End Sub Protected Sub button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i, n As Integer
i = 0
n = L_ListBox.Items.Count
While n > 0
R_ListBox.Items.Add(L_ListBox.Items(i))
L_ListBox.Items.Remove(L_ListBox.Items(i))
n = n - 1
End While
End Sub Protected Sub button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim i, n As Integer
i = 0
n = R_ListBox.Items.Count - 1
While i <= n
If (R_ListBox.Items(i).Selected) Then
L_ListBox.Items.Add(R_ListBox.Items(i))
R_ListBox.Items.Remove(R_ListBox.Items(i))
L_ListBox.Items(L_ListBox.Items.Count - 1).Selected = False
n = n - 1
Else
i = i + 1 End If
End While
End Sub Protected Sub button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim i, n As Integer
i = 0
n = R_ListBox.Items.Count
While n > 0
L_ListBox.Items.Add(R_ListBox.Items(i))
R_ListBox.Items.Remove(R_ListBox.Items(i))
n = n - 1
End While
End Sub
End Class
参数主要有三个:左右两个listbox和数据源
控件的值是右边listbox中的项。<body>
<form id="form1" runat="server">
<div>
<table style="width: 472px; height: 176px">
<tr>
<td rowspan="3" style="width: 100px">
<asp:ListBox ID="L_ListBox" runat="server" DataSourceID="SqlDataSource1" DataTextField="LastName"
DataValueField="LastName" Height="100px" Width="150px"></asp:ListBox><asp:SqlDataSource
ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString4 %>"
SelectCommand="SELECT [LastName] FROM [Employees]"></asp:SqlDataSource>
</td>
<td rowspan="3" style="width: 100px">
<table>
<tr>
<td style="width: 100px">
<asp:Button ID="Button1" runat="server" Text=">>" Width="50px" /></td>
</tr>
<tr>
<td style="width: 100px">
<asp:Button ID="Button2" runat="server" Text=">>>>" Width="50px" /></td>
</tr>
<tr>
<td style="width: 100px">
<asp:Button ID="Button3" runat="server" Text="<<" Width="50px" /></td>
</tr>
<tr>
<td style="width: 100px">
<asp:Button ID="Button4" runat="server" Text="<<<<" Width="50px" /></td>
</tr>
</table>
</td>
<td rowspan="3" style="width: 100px">
<asp:ListBox ID="R_ListBox" runat="server" Height="100px" Width="150px"></asp:ListBox></td>
</tr>
<tr>
</tr>
<tr>
</tr>
</table>
</div>
</form>
</body>
-------------以下是vb代码-----------------------------
Partial Class Default4
Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Protected Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i, n As Integer
i = 0
n = L_ListBox.Items.Count - 1
While i <= n
If L_ListBox.Items(i).Selected Then
R_ListBox.Items.Add(L_ListBox.Items(i))
L_ListBox.Items.Remove(L_ListBox.Items(i))
R_ListBox.Items(R_ListBox.Items.Count - 1).Selected = False
n = n - 1
Else
i = i + 1
End If
End While
End Sub Protected Sub button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i, n As Integer
i = 0
n = L_ListBox.Items.Count
While n > 0
R_ListBox.Items.Add(L_ListBox.Items(i))
L_ListBox.Items.Remove(L_ListBox.Items(i))
n = n - 1
End While
End Sub Protected Sub button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim i, n As Integer
i = 0
n = R_ListBox.Items.Count - 1
While i <= n
If (R_ListBox.Items(i).Selected) Then
L_ListBox.Items.Add(R_ListBox.Items(i))
R_ListBox.Items.Remove(R_ListBox.Items(i))
L_ListBox.Items(L_ListBox.Items.Count - 1).Selected = False
n = n - 1
Else
i = i + 1 End If
End While
End Sub Protected Sub button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim i, n As Integer
i = 0
n = R_ListBox.Items.Count
While n > 0
L_ListBox.Items.Add(R_ListBox.Items(i))
R_ListBox.Items.Remove(R_ListBox.Items(i))
n = n - 1
End While
End Sub
End Class
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货