本文介绍了使用DropDownlist SelectedItem更改Gridview上的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Imports System.Data
Imports System.Data.SqlClient
Partial Class testing
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Me.BindData()
End If
End Sub
Private Sub BindData()
Dim Query As String = "Select * from Employees"
Dim Cmd As New SqlCommand(Query)
GridView1.DataSource = GetData(Cmd)
GridView1.DataBind()
End Sub
Private Function GetData(ByVal Cmd As SqlCommand) As DataTable
Dim strConnString As String = ConfigurationManager.ConnectionStrings("conString").ConnectionString
Using con As New SqlConnection(strConnString)
Using sda As New SqlDataAdapter()
Cmd.Connection = con
sda.SelectCommand = Cmd
Using dt As New DataTable()
sda.Fill(dt)
Return dt
End Using
End Using
End Using
End Function
End Class
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="testing.aspx.vb" Inherits="testing" %>
<!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">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" Height="22px" Width="78px"
DataSourceID="SqlDataSource1" DataTextField="Employee_Name"
DataValueField="Employee_Name">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:wilshireConnectionString4 %>"
SelectCommand="SELECT Employee_Name FROM Employees"></asp:SqlDataSource>
<br />
<br />
<br />
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>
</form>
</body>
</html>
推荐答案
这篇关于使用DropDownlist SelectedItem更改Gridview上的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!