使用DropDownlist SelectedItem更改Gridview上的值 [英] Change values on Gridview using DropDownlist SelectedItem

查看:52
本文介绍了使用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>

推荐答案

ConnectionStrings:wilshireConnectionString4 %> " span> =" 从雇员中选择Employee_Name" ">< /asp:SqlDataSource > < br > < br > < br > < asp:GridView ID =" runat 服务器" < /asp:GridView > < /div > < /form > < /body > < /html >
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>


我想在没有任何posstback方法的情况下通过dropdownlistSelectedItem来更改gridview值. 请您重新编写代码.
否.没有人会为您重新编写代码.我们肯定可以说出它是如何做到的.您必须自己尝试.

您需要使用AJAX.您去了:
MS:AJAX视频 [ ^ ]
Ajax教程 [ ^ ]
AJAX概述 [什么是ASP.NET Ajax? [ UpdatePanel控件 [ UpdatePanel类 [
I wanted to change the gridview values with effecting of dropdownlistSelectedItem with out any posstback method. Can you please re-write the code.
No. Nobody is going to re-write the code for you. We surely can tell how it can be done. You have to try by yourself.

You need to use AJAX. Here you go:
MS: AJAX Videos[^]
Ajax tutorials[^]
AJAX overview[^]
What is ASP.NET Ajax?[^]

Keeping small things aside, in short, you need to put your Grid in an Udpate Panel to enable partial rendering:
UpdatePanel control[^]
UpdatePanel Class[^]
All you need to know with sample code is present and explained.


这篇关于使用DropDownlist SelectedItem更改Gridview上的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆