GridView备用数据源 [英] Gridview alternate datasource

查看:66
本文介绍了GridView备用数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
首先.我对ASP.NET非常陌生,请耐心等待.

场景:向用户显示一个网页,询问客户编号,然后单击执行"按钮. 转到"按钮将调用另一个页面,并将客户编号传递到该页面.该页面加载了gridview. girdview的数据源将加载sqlsource.源调用存储过程,并将数据传递回由先前获得的客户编号过滤的Gridview.这是棘手的地方. Gridview显示了从sql服务器中现有表提取的过程中的一些数据.在点击编辑按钮后,还必须填充一些空白字段.一旦用户填充了字段Update/insert,并且插入过程将使用添加的字段数据记录,并将其插入sql数据库的适当表中.现在我需要的是gridview,以显示一个刚刚插入到新表中的更新记录,方法是调用一个调用数据源,并传递用户在空字段中输入的序列号.

PS.我使用VB.

下面是aspx和aspx.vb文件,因为我现在拥有它们. sqldatasource3是需要传递序列号以获取单独的sql表中更新的记录的源.

我非常满意,或者您可以给我任何帮助.

〜安东尼

Hello,
First of all. Im very new to ASP.NET so bear with me.

Scenario: User is presented with a web page asking for a customer number and then hits a go button. The Go button calls another page and passes on the customer number to that page. The page loads a gridview . THe girdview''s datasourece loads an sqlsource. The source calls a stored procedure and passes the data back to the gridview filtered by the previoulsy obtained customer number. Here is where it gets tricky. The Gridview shows some data the procedure pulled from an existing table in the sql server. There are also some empty fields that after hitting the edit buttton, the user has to populate. Once the user populates the fields Update/insert is selected and the the insert procedure takes the record wiht added field data and inserts it into a speerate table in the sql database. WHat i need now is the gridview to show the updated record i just inserted into the new table by calling a didfferent datasource passing on the serial number the user has entered in the of the empty fields.

PS. i use VB.

below is the aspx and aspx.vb file as i have them now. THe sqldatasource3 is the source that the serial number needs to be passed on to to obtain the updatyed records in the separate sql table.

I am greatfull or any help you can give me.

~Anthony

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="REWTSCusNum.aspx.vb" Inherits="REWTSEquip" %>

<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    </div>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

        DataSourceID="REWTSEquip1" EnableModelValidation="True" AllowPaging="True"

        AutoGenerateEditButton="True" PageSize="4" Height="150px">
        <Columns>
            <asp:TemplateField HeaderText="MANUFACTURER" SortExpression="MANUFACTURER">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" maxlength='25'   Text='<%# Bind("MANUFACTURER") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("MANUFACTURER") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="MODEL" SortExpression="MODEL">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" maxlength='5'  Text='<%# Bind("MODEL") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("MODEL") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="DESCRIPTION" SortExpression="DESCRIPTION">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox3" runat="server" maxlength='25'   Text='<%# Bind("DESCRIPTION") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("DESCRIPTION") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="SERIAL" SortExpression="SERIAL">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox4" runat="server" maxlength='12'   Text='<%# Bind("SERIAL") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label4" runat="server" Text='<%# Bind("SERIAL") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="EQUIP_ID" SortExpression="EQUIP_ID">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox5" runat="server" maxlength='5'  Text='<%# Bind("EQUIP_ID") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label5" runat="server"   Text='<%# Bind("EQUIP_ID") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="CUSTOMER_NUMBER"

                SortExpression="CUSTOMER_NUMBER">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox6" runat="server"  maxlength='6' Text='<%# Bind("CUSTOMER_NUMBER") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label6" runat="server"   Text='<%# Bind("CUSTOMER_NUMBER") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="SERVICECOUNT" SortExpression="SERVICECOUNT">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox7" runat="server" maxlength='6'   Text='<%# Bind("SERVICECOUNT") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label7" runat="server" Text='<%# Bind("SERVICECOUNT") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="LOCATION" SortExpression="LOCATION">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox8" runat="server"  maxlength='6' Text='<%# Bind("LOCATION") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label8" runat="server"  Text='<%# Bind("LOCATION") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="RECEIVED" SortExpression="RECEIVED">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox9" runat="server" Text='<%# Bind("RECEIVED") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label9" runat="server" Text='<%# Bind("RECEIVED") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
           <asp:TemplateField HeaderText="CONDITION" SortExpression="CONDITION">
                    <EditItemTemplate>
                        <asp:DropDownList ID="DropDownList1" runat="server"

                            DataSourceID="SqlDataSource1" DataTextField="CONDITION"

                            DataValueField="CONDITION" SelectedValue='<%# Bind("CONDITION") %>'>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label10" runat="server" Text='<%# Bind("CONDITION") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
            <asp:TemplateField HeaderText="TECHNICIAN" SortExpression="TECHNICIAN">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox11" runat="server"  maxlength='6'  Text='<%# Bind("TECHNICIAN") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label11" runat="server" Text='<%# Bind("TECHNICIAN") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="NOTES" SortExpression="NOTES">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox12" runat="server" maxlength='50'  Text='<%# Bind("NOTES") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label12" runat="server" Text='<%# Bind("NOTES") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="DISPOSITION" SortExpression="DISPOSITION">
                    <EditItemTemplate>
                        <asp:DropDownList ID="DropDownList2" runat="server"

                            DataSourceID="SqlDataSource2" DataTextField="DISPOSITION"

                            DataValueField="DISPOSITION" SelectedValue='<%# Bind("DISPOSITION") %>'>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label13" runat="server" Text='<%# Bind("DISPOSITION") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="REWTSEquip1" runat="server"

        ConnectionString="<%$ ConnectionStrings:REWTSEquipConnectString %>"

        SelectCommand="usp_REWTSSerialEquipByCUSNUM"

        SelectCommandType="StoredProcedure"



        InsertCommand="INSERT INTO REWTSEquipment(MANUFACTURER, MODEL, DESCRIPTION, SERIAL, EQUIP_ID, CUSTOMER_NUMBER, SERVICECOUNT, LOCATION, RECEIVED, CONDITION, TECHNICIAN, NOTES, DISPOSITION) VALUES (@MANUFACTURER, @MODEL, @DESCRIPTION, @SERIAL, @EQUIP_ID, @CUSTOMER_NUMBER, @SERVICECOUNT, @LOCATION, @RECEIVED, @CONDITION, @TECHNICIAN, @NOTES, @DISPOSITION)"



        UpdateCommand="INSERT INTO REWTSEquipment(MANUFACTURER, MODEL, DESCRIPTION, SERIAL, EQUIP_ID, CUSTOMER_NUMBER, SERVICECOUNT, LOCATION, RECEIVED, CONDITION, TECHNICIAN, NOTES, DISPOSITION) VALUES (@MANUFACTURER, @MODEL, @DESCRIPTION, @SERIAL, @EQUIP_ID, @CUSTOMER_NUMBER, @SERVICECOUNT, @LOCATION, @RECEIVED, @CONDITION, @TECHNICIAN, @NOTES, @DISPOSITION)">
        <InsertParameters>
            <asp:Parameter Name="MANUFACTURER" />
            <asp:Parameter Name="MODEL" />
            <asp:Parameter Name="DESCRIPTION" />
            <asp:Parameter Name="SERIAL" />
            <asp:Parameter Name="EQUIP_ID" />
            <asp:Parameter Name="CUSTOMER_NUMBER" />
            <asp:Parameter Name="SERVICECOUNT" />
            <asp:Parameter Name="LOCATION" />
            <asp:Parameter Name="RECEIVED" />
            <asp:Parameter Name="CONDITION" />
            <asp:Parameter Name="TECHNICIAN" />
            <asp:Parameter Name="NOTES" />
            <asp:Parameter Name="DISPOSITION" />
        </InsertParameters>
        <SelectParameters>
            <asp:QueryStringParameter Name="CUSNUM" QueryStringField="CusNum"

                Type="String" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="MANUFACTURER" />
            <asp:Parameter Name="MODEL" />
            <asp:Parameter Name="DESCRIPTION" />
            <asp:Parameter Name="SERIAL" />
            <asp:Parameter Name="EQUIP_ID" />
            <asp:Parameter Name="CUSTOMER_NUMBER" />
            <asp:Parameter Name="SERVICECOUNT" />
            <asp:Parameter Name="LOCATION" />
            <asp:Parameter Name="RECEIVED" />
            <asp:Parameter Name="CONDITION" />
            <asp:Parameter Name="TECHNICIAN" />
            <asp:Parameter Name="NOTES" />
            <asp:Parameter Name="DISPOSITION" />
        </UpdateParameters>
    </asp:SqlDataSource>

        <asp:SqlDataSource ID="SqlDataSource1" runat="server"

            ConnectionString="<%$ ConnectionStrings:REWTSConnectionString3 %>"

            SelectCommand="SELECT [CONDITION] FROM [tbl_Condition]"></asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server"

            ConnectionString="<%$ ConnectionStrings:REWTSConnectionString3 %>"

            SelectCommand="SELECT [DISPOSITION] FROM [tbl_DISPOSITION]">
        </asp:SqlDataSource>

    <asp:SqlDataSource ID="SqlDataSource3" runat="server"

        ConnectionString="<%$ ConnectionStrings:REWTSConnectionString5 %>"

        SelectCommand="SELECT * FROM [REWTSEquipment] WHERE ([SERIAL] = @SERIAL)">
        <SelectParameters>
            <asp:ControlParameter ControlID="GridView1" Name="SERIAL"

                PropertyName="SelectedValue" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>

    <br />
        <asp:Button ID="btnLogout0" runat="server" OnClick="btnLogout_OnClick" text="Log Out" />
           <asp:Button ID="Button1" runat="server" Text="BACK" />
    </form>
</body>
</html>



===============================================
代码隐藏




=================================================
CODE BEHIND


Partial Class REWTSEquip
    Inherits System.Web.UI.Page

    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged

    End Sub

    'logout subroutine
    Sub btnLogout_OnClick(ByVal Src As Object, ByVal E As EventArgs) Handles btnLogout0.Click
        FormsAuthentication.SignOut()
        Response.Redirect("Default.aspx")
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Response.Redirect("REWTSSHEET.aspx")
    End Sub

    Protected Sub SqlDataSource1_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles SqlDataSource1.Selecting

    End Sub
End Class

推荐答案

ConnectionStrings:REWTSEquipConnectString %>" SelectCommand="usp_REWTSSerialEquipByCUSNUM" SelectCommandType="StoredProcedure" InsertCommand="INSERT INTO REWTSEquipment(MANUFACTURER, MODEL, DESCRIPTION, SERIAL, EQUIP_ID, CUSTOMER_NUMBER, SERVICECOUNT, LOCATION, RECEIVED, CONDITION, TECHNICIAN, NOTES, DISPOSITION) VALUES (@MANUFACTURER, @MODEL, @DESCRIPTION, @SERIAL, @EQUIP_ID, @CUSTOMER_NUMBER, @SERVICECOUNT, @LOCATION, @RECEIVED, @CONDITION, @TECHNICIAN, @NOTES, @DISPOSITION)" UpdateCommand="INSERT INTO REWTSEquipment(MANUFACTURER, MODEL, DESCRIPTION, SERIAL, EQUIP_ID, CUSTOMER_NUMBER, SERVICECOUNT, LOCATION, RECEIVED, CONDITION, TECHNICIAN, NOTES, DISPOSITION) VALUES (@MANUFACTURER, @MODEL, @DESCRIPTION, @SERIAL, @EQUIP_ID, @CUSTOMER_NUMBER, @SERVICECOUNT, @LOCATION, @RECEIVED, @CONDITION, @TECHNICIAN, @NOTES, @DISPOSITION)"> < InsertParameters > <asp:Parameter Name="MANUFACTURER" /> <asp:Parameter Name="MODEL" /> <asp:Parameter Name="DESCRIPTION" /> <asp:Parameter Name="SERIAL" /> <asp:Parameter Name="EQUIP_ID" /> <asp:Parameter Name="CUSTOMER_NUMBER" /> <asp:Parameter Name="SERVICECOUNT" /> <asp:Parameter Name="LOCATION" /> <asp:Parameter Name="RECEIVED" /> <asp:Parameter Name="CONDITION" /> <asp:Parameter Name="TECHNICIAN" /> <asp:Parameter Name="NOTES" /> <asp:Parameter Name="DISPOSITION" /> < /InsertParameters > < SelectParameters > <asp:QueryStringParameter Name="CUSNUM" QueryStringField="CusNum" Type="String" /> < /SelectParameters > < UpdateParameters > <asp:Parameter Name="MANUFACTURER" /> <asp:Parameter Name="MODEL" /> <asp:Parameter Name="DESCRIPTION" /> <asp:Parameter Name="SERIAL" /> <asp:Parameter Name="EQUIP_ID" /> <asp:Parameter Name="CUSTOMER_NUMBER" /> <asp:Parameter Name="SERVICECOUNT" /> <asp:Parameter Name="LOCATION" /> <asp:Parameter Name="RECEIVED" /> <asp:Parameter Name="CONDITION" /> <asp:Parameter Name="TECHNICIAN" /> <asp:Parameter Name="NOTES" /> <asp:Parameter Name="DISPOSITION" /> < /UpdateParameters > < /asp:SqlDataSource > < asp:SqlDataSource ID =" runat 服务器" ConnectionString="<%
ConnectionStrings:REWTSEquipConnectString %>" SelectCommand="usp_REWTSSerialEquipByCUSNUM" SelectCommandType="StoredProcedure" InsertCommand="INSERT INTO REWTSEquipment(MANUFACTURER, MODEL, DESCRIPTION, SERIAL, EQUIP_ID, CUSTOMER_NUMBER, SERVICECOUNT, LOCATION, RECEIVED, CONDITION, TECHNICIAN, NOTES, DISPOSITION) VALUES (@MANUFACTURER, @MODEL, @DESCRIPTION, @SERIAL, @EQUIP_ID, @CUSTOMER_NUMBER, @SERVICECOUNT, @LOCATION, @RECEIVED, @CONDITION, @TECHNICIAN, @NOTES, @DISPOSITION)" UpdateCommand="INSERT INTO REWTSEquipment(MANUFACTURER, MODEL, DESCRIPTION, SERIAL, EQUIP_ID, CUSTOMER_NUMBER, SERVICECOUNT, LOCATION, RECEIVED, CONDITION, TECHNICIAN, NOTES, DISPOSITION) VALUES (@MANUFACTURER, @MODEL, @DESCRIPTION, @SERIAL, @EQUIP_ID, @CUSTOMER_NUMBER, @SERVICECOUNT, @LOCATION, @RECEIVED, @CONDITION, @TECHNICIAN, @NOTES, @DISPOSITION)"> <InsertParameters> <asp:Parameter Name="MANUFACTURER" /> <asp:Parameter Name="MODEL" /> <asp:Parameter Name="DESCRIPTION" /> <asp:Parameter Name="SERIAL" /> <asp:Parameter Name="EQUIP_ID" /> <asp:Parameter Name="CUSTOMER_NUMBER" /> <asp:Parameter Name="SERVICECOUNT" /> <asp:Parameter Name="LOCATION" /> <asp:Parameter Name="RECEIVED" /> <asp:Parameter Name="CONDITION" /> <asp:Parameter Name="TECHNICIAN" /> <asp:Parameter Name="NOTES" /> <asp:Parameter Name="DISPOSITION" /> </InsertParameters> <SelectParameters> <asp:QueryStringParameter Name="CUSNUM" QueryStringField="CusNum" Type="String" /> </SelectParameters> <UpdateParameters> <asp:Parameter Name="MANUFACTURER" /> <asp:Parameter Name="MODEL" /> <asp:Parameter Name="DESCRIPTION" /> <asp:Parameter Name="SERIAL" /> <asp:Parameter Name="EQUIP_ID" /> <asp:Parameter Name="CUSTOMER_NUMBER" /> <asp:Parameter Name="SERVICECOUNT" /> <asp:Parameter Name="LOCATION" /> <asp:Parameter Name="RECEIVED" /> <asp:Parameter Name="CONDITION" /> <asp:Parameter Name="TECHNICIAN" /> <asp:Parameter Name="NOTES" /> <asp:Parameter Name="DISPOSITION" /> </UpdateParameters> </asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%


ConnectionStrings:REWTSConnectionString3 %>" SelectCommand="SELECT [CONDITION] FROM [tbl_Condition]"></asp:SqlDataSource> < asp:SqlDataSource ID =" runat 服务器" ConnectionString="<%
ConnectionStrings:REWTSConnectionString3 %>" SelectCommand="SELECT [CONDITION] FROM [tbl_Condition]"></asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%


ConnectionStrings:REWTSConnectionString3 %>" SelectCommand="SELECT [DISPOSITION] FROM [tbl_DISPOSITION]"> < /asp:SqlDataSource > < asp:SqlDataSource ID =" runat 服务器" ConnectionString="<%
ConnectionStrings:REWTSConnectionString3 %>" SelectCommand="SELECT [DISPOSITION] FROM [tbl_DISPOSITION]"> </asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%


这篇关于GridView备用数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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