0 Replies - 1560 Views - Last Post: 05 December 2016 - 01:40 PM Rate Topic: -----

#1 Jeff_the_creator  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 07-September 16

Insert saved information on bound SQL column in GridView when editing.

Posted 05 December 2016 - 01:40 PM

Hello All,

I have a grid-view which is populated by a datasource query from a SQLserver DB. When i pull the gridview i want to be able to make it editable for the user so they can send new information along back to the SQL server. When the user hits edit on the Gridview i want two of the bound columns "OperatorSubmitDate" and "OperatorName" to be able to be pre-populated so they do not have to enter the information. For the "OperatorSubmitDate" i would like it to show the current date and for "OperatorName" display the current session being passed to the page for the login screen. For the life of me i cant get my gridview to populate on load with this when i click the edit link on the table to make the gridview changes.

Here's my code so far any help would be greatly appreciated:
Html Code:
 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="uid" DataSourceID="SqlDataSource1" CellPadding="4" ForeColor="#333333" GridLines="None" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating">
        <AlternatingRowStyle BackColor="White" />
        <Columns>
            <asp:BoundField DataField="uid" HeaderText="uid" InsertVisible="False" ReadOnly="True" SortExpression="uid" />
            <asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" />
            <asp:BoundField DataField="EngineeringSupport" HeaderText="EngineeringSupport" SortExpression="EngineeringSupport" />
            <asp:TemplateField HeaderText="OperatorSubmitDate" SortExpression="OperatorSubmitDate">
                <EditItemTemplate>    
            <asp:TextBox ID="TextBox2" runat="server" Text='<%# Convert.ToDateTime(Eval("OperatorSubmitDate")).ToString%>'</asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("OperatorSubmitDate") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="OperatorName" SortExpression="OperatorName">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("OperatorName") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("OperatorName") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="Actual" HeaderText="Actual" SortExpression="Actual" />
            <asp:TemplateField HeaderText="Status" SortExpression="Status">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("Status") %>' onselectedIndexChanged="DropDownList1_SelectedIndexChanged">
                        <asp:ListItem>REWORK NEEDED</asp:ListItem>
                        <asp:ListItem>REWORK COLMELTED</asp:ListItem>
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("Status") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:CommandField ShowEditButton="True" />
        </Columns>
    </asp:GridView>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CoatingDefectTrackerDBConnectionString %>" 
        DeleteCommand="DELETE FROM [userTD] WHERE [uid] = @uid" 
        InsertCommand="INSERT INTO [userTD] ([Date], [Status], [EngineeringSupport], [OperatorSubmitDate], [OperatorName], [Actual]) VALUES (@Date, @Status, @EngineeringSupport, @OperatorSubmitDate, @OperatorName, @Actual)" 
        SelectCommand="SELECT [uid], [Date], [Status], [EngineeringSupport], [OperatorSubmitDate], [OperatorName], [Actual] FROM [userTD] WHERE ([uid] = @uid)" 
        UpdateCommand="UPDATE [userTD] SET [Date] = @Date, [Status] = @Status, [EngineeringSupport] = @EngineeringSupport, [OperatorSubmitDate] = @OperatorSubmitDate, [OperatorName] = @OperatorName, [Actual] = @Actual WHERE [uid] = @uid">
        <DeleteParameters>
            <asp:Parameter Name="uid" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="Date" Type="String" />
            <asp:Parameter Name="Status" Type="String" />
            <asp:Parameter Name="EngineeringSupport" Type="String" />
            <asp:Parameter Name="OperatorSubmitDate" Type="String" />
            <asp:Parameter Name="OperatorName" Type="String" />
            <asp:Parameter Name="Actual" Type="String" />
        </InsertParameters>
        <SelectParameters>
                 <asp:QueryStringParameter Name="uid" QueryStringField="cat" Type="Int32" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="Date" Type="String" />
            <asp:Parameter Name="Status" Type="String" />
            <asp:Parameter Name="EngineeringSupport" Type="String" />
            <asp:Parameter Name="OperatorSubmitDate" Type="String" />
            <asp:Parameter Name="OperatorName" Type="String" />
            <asp:Parameter Name="Actual" Type="String" />
            <asp:Parameter Name="uid" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>


VB Code:
 Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        Dim UN As String = CType(Session.Item("LogInInfo"), String)
        con.ConnectionString = "Data Source=DARTH;Initial Catalog=CoatingDefectTrackerDB;Persist Security Info=True;User    ID=coatingDTAdmin;Password=coatingAdminU$er16"

GridView1.Rows(0).Cells(7).Text = Date.Today
GridView1.Rows(0).Cells(8).Text = UN

End Sub



Is This A Good Question/Topic? 0
  • +

Page 1 of 1