Click here to Skip to main content
15,894,540 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

XML
<%@ 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


VB
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
Posted
Comments
Maciej Los 27-Jun-11 12:14pm    
If you can load data and view it in DataGridView, where is the problem?
Do you need help with sql command: "SELECT * FROM [REWTSEquipment] WHERE ([SERIAL] = @SERIAL" ?

Do you want to apply 2 datasources to single Grid? if it is so then it is not possible. If you are using Grid within Grid then it is possible.

Also your question is not clear, what you want to do exactly. I believe you should do some googling for your problem. If you are new to ASP.Net, go with some ASP.Net beginner book.
 
Share this answer
 
I am opening a page containing a gridview that is populated using an sqldatasource and a parameter obtain from the the preceding page. When the grid is populated, the user has the option to edit any of the records in the gridview. When the user edits a record and hits update, what really happens is that the updated record is actually written to a different table in sql. Not the original source table. What i want to happen is that if a user hits the UPDATE control in the gridview the gridview needs to return the record as it was edited from the new table. I can't explain it any simpler than this. So in essence what i need to have happen is that when a user edits a record the gridview needs to remember that record (SERIAL which is a column in the girdview) and after the user hits update the code needs to grab the serial value and pass that to a second sqldatasource and retrirve that record from the new table and populate the gridview with it. i dont care if we have to hide the original gridview and call up a second gridview on the same page . hope this makes more sense.

Thank you.
 
Share this answer
 
just repopulate the grid with the same id which you have when the page load :)
 
Share this answer
 
Comments
AnthonyGC 13-Jul-11 10:21am    
Ok, any more suggestions? Could I try and work with a page reload fucntion to accomplish this?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900