Click here to Skip to main content
15,305,430 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Folks this one has me baffled but that's not hard considering I've been away from code for about 5 years and now just getting pushed back into it (willingly). A lot has changed but I think I've covered all the bases here but this should have worked somewhere along the line but it doesn't.

It was working at one point but I made some formatting changed and broke it. Despite reversing back though the changes nothing fixed the break. HELP!!!

Here's what I have...

Simple gridview really aside from having several template fields in it for drop down boxed and a check box (currently turned off due to a format nightmare I'm also dealing with). The gridview is driven by a standard SqlDataSource connection with methods built for insert, update, and delete.

I've followed exampled I have found on the web nada... I've added a code behind handler to kick it a it with it's own prompting to update. I even went as far as to try and pull off a session variable to then feed that back into the method to tell it what record to write (which shouldn't be necessary) that didn't work.

Can someone take a peek and tell me what they see as the problem here and give me some pointers. I'm a bit rusty and could use some help.

Regards,
Ken...

Below is the code behind page and the aspx page...

ASPX page:
ASP.NET
<%@ Page Title="Gap Document Revew Page" Language="vb" AutoEventWireup="true" MasterPageFile="~/Site.Master" CodeBehind="GapDocument.aspx.vb" Inherits="GETTWeb.GapDocument" EnableSessionState="True" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

    <table style="width: 100%;">
        <tr>
            <td>Family:</td>
            <td>Article:</td>
            <td>Document Title:</td>
            <td>Insert Element:</td>
        </tr>
        <tr>
            <td>
                <asp:Label ID="FamilyLabel" runat="server" Text="Label" Font-Size="Large"></asp:Label></td>
            <td>
                <asp:Label ID="ArticleLabel" runat="server" Text="Label" Font-Size="Large"></asp:Label></td>
            <td>
                <asp:Label ID="DocumentTitleLabel" runat="server" Text="Label" Font-Size="Large"></asp:Label></td>
            <td>
                <asp:HyperLink ID="hyperlink1"
                    ImageUrl="AddNewButton175x80.jpg"
                    NavigateUrl="~/NewDocument.aspx"
                    Text="New Element Review Document"
                    Target="_blank"
                    runat="server" ImageWidth="79" ImageHeight="36" />
            </td>
        </tr>
    </table>
    <br />
    <asp:GridView ID="GridView1" runat="server" DataSourceID="GapDocDataSource" AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True">
        <Columns>
            <%-----------------------------------------------------------------------------------------------------------------%>
            <asp:CommandField ShowSelectButton="True" 
                AccessibleHeaderText="Refer To Article" 
                SelectText="View" 
                HeaderImageUrl="~/Article51x36b.gif" 
                HeaderStyle-HorizontalAlign="Center" 
                ItemStyle-HorizontalAlign="Center" 
                HeaderStyle-BackColor="#0066FF" />
            <%-----------------------------------------------------------------------------------------------------------------%>
            <asp:BoundField DataField="DElement_Sub" 
                HeaderText="Ele" 
                SortExpression="DElement_Sub" 
                ItemStyle-HorizontalAlign="Center" 
                ItemStyle-Width="15" ReadOnly="True" />
            <%-----------------------------------------------------------------------------------------------------------------%>
            <asp:BoundField DataField="DocID" 
                HeaderText="Doc ID" 
                SortExpression="DocID" 
                ApplyFormatInEditMode="True" 
                ReadOnly="True" 
                ItemStyle-HorizontalAlign="Center" 
                HeaderStyle-HorizontalAlign="Center">
                <HeaderStyle HorizontalAlign="Center" />
            </asp:BoundField>
            <%-----------------------------------------------------------------------------------------------------------------%>
            <asp:BoundField DataField="Doc_Name" 
                HeaderText="Support Document" 
                SortExpression="Doc_Name" 
                ControlStyle-Width="200" />
            <%-----------------------------------------------------------------------------------------------------------------%>
            <asp:BoundField DataField="Doc_Section" 
                HeaderText="Refer To Section(s)" 
                SortExpression="Doc_Section" 
                ControlStyle-Width="200" />
            <%-----------------------------------------------------------------------------------------------------------------%>
            <asp:TemplateField HeaderText="ENote" 
                SortExpression="Enote" ControlStyle-Width="200">
               <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ENote") %>'></asp:TextBox>
               </EditItemTemplate>
               <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("ENote") %>'></asp:Label>
               </ItemTemplate>
            </asp:TemplateField>
            <%-----------------------------------------------------------------------------------------------------------------%>
            <asp:TemplateField HeaderText="<center>N / A</center>" SortExpression="NotApply" Visible="False">
               <EditItemTemplate>
                   
                    <asp:CheckBox runat="server" ID="CheckBox2"
                        Checked='<%#(Eval("NotApply").ToString()) %>'
                        Width="50px" CssClass="checkbox"></asp:CheckBox>
               </EditItemTemplate>
               <ItemTemplate>
                    <asp:CheckBox runat="server" ID="CheckBox1"
                        Checked='<%#(Eval("NotApply").ToString())%>'
                        Width="50px" CssClass="checkbox"></asp:CheckBox>
                </ItemTemplate>
            </asp:TemplateField>
            <%-----------------------------------------------------------------------------------------------------------------%>
            <asp:TemplateField HeaderText="BCBS <br />MS-Windows <br />Net" SortExpression="Windows_C">
               <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" SelectedIndex='<%# Bind("Windows_C") %>'>
                        <asp:ListItem>N/A</asp:ListItem>
                        <asp:ListItem>Gap</asp:ListItem>
                        <asp:ListItem>Upd</asp:ListItem>
                        <asp:ListItem>Current</asp:ListItem>
                    </asp:DropDownList>
                    </EditItemTemplate>
               <ItemTemplate>
                    <asp:DropDownList ID="DropDownList2" runat="server" SelectedIndex='<%# Bind("Windows_C") %>'>
                        <asp:ListItem>N/A</asp:ListItem>
                        <asp:ListItem>Gap</asp:ListItem>
                        <asp:ListItem>Upd</asp:ListItem>
                        <asp:ListItem>Current</asp:ListItem>
                    </asp:DropDownList>
               </ItemTemplate>
            </asp:TemplateField>
            <%-----------------------------------------------------------------------------------------------------------------%>
            <asp:TemplateField HeaderText="Cahaba <br />MS-Window <br />Net" SortExpression="Windows_G">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList3" runat="server" SelectedIndex='<%# Bind("Windows_G") %>'>
                        <asp:ListItem>N/A</asp:ListItem>
                        <asp:ListItem>Gap</asp:ListItem>
                        <asp:ListItem>Upd</asp:ListItem>
                        <asp:ListItem>Current</asp:ListItem>
                    </asp:DropDownList>
                    <%--                          The old text box for Edit                                       --%>
                    <%-- <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Windows_G") %>'></asp:TextBox> --%>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:DropDownList ID="DropDownList4" runat="server" SelectedIndex='<%# Bind("Windows_G") %>'>
                        <asp:ListItem>N/A</asp:ListItem>
                        <asp:ListItem>Gap</asp:ListItem>
                        <asp:ListItem>Upd</asp:ListItem>
                        <asp:ListItem>Current</asp:ListItem>
                    </asp:DropDownList>
                    <%-- This was the code remarked out from the conversion of the field to template         --%>
                    <%-- <asp:Label ID="Label2" runat="server" Text='<%# Bind("Windows_G") %>'></asp:Label>  --%>
                </ItemTemplate>
            </asp:TemplateField>
            <%-----------------------------------------------------------------------------------------------------------------%>
            <asp:TemplateField HeaderText="Call Center <br />MS-Windows <br />Net" SortExpression="Windows_U">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList5" runat="server" SelectedIndex='<%# Bind("Windows_U") %>'>
                        <asp:ListItem>N/A</asp:ListItem>
                        <asp:ListItem>Gap</asp:ListItem>
                        <asp:ListItem>Upd</asp:ListItem>
                        <asp:ListItem>Current</asp:ListItem>
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:DropDownList ID="DropDownList6" runat="server" SelectedIndex='<%# Bind("Windows_U") %>'>
                        <asp:ListItem>N/A</asp:ListItem>
                        <asp:ListItem>Gap</asp:ListItem>
                        <asp:ListItem>Upd</asp:ListItem>
                        <asp:ListItem>Current</asp:ListItem>
                    </asp:DropDownList>
                </ItemTemplate>
            </asp:TemplateField>
            <%-----------------------------------------------------------------------------------------------------------------%>
            <asp:TemplateField HeaderText="UNIX" SortExpression="UNIX">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList7" runat="server" SelectedIndex='<%# Bind("UNIX") %>'>
                        <asp:ListItem>N/A</asp:ListItem>
                        <asp:ListItem>Gap</asp:ListItem>
                        <asp:ListItem>Upd</asp:ListItem>
                        <asp:ListItem>Current</asp:ListItem>
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:DropDownList ID="DropDownList8" runat="server" SelectedIndex='<%# Bind("UNIX") %>'>
                        <asp:ListItem>N/A</asp:ListItem>
                        <asp:ListItem>Gap</asp:ListItem>
                        <asp:ListItem>Upd</asp:ListItem>
                        <asp:ListItem>Current</asp:ListItem>
                    </asp:DropDownList>
                </ItemTemplate>
            </asp:TemplateField>
            <%-----------------------------------------------------------------------------------------------------------------%>
            <asp:TemplateField HeaderText="Mainframe" SortExpression="Mainframe">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList9" runat="server" SelectedIndex='<%# Bind("Mainframe") %>'>
                        <asp:ListItem>N/A</asp:ListItem>
                        <asp:ListItem>Gap</asp:ListItem>
                        <asp:ListItem>Upd</asp:ListItem>
                        <asp:ListItem>Current</asp:ListItem>
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:DropDownList ID="DropDownList10" runat="server" SelectedIndex='<%# Bind("Mainframe") %>'>
                        <asp:ListItem>N/A</asp:ListItem>
                        <asp:ListItem>Gap</asp:ListItem>
                        <asp:ListItem>Upd</asp:ListItem>
                        <asp:ListItem>Current</asp:ListItem>
                    </asp:DropDownList>
                </ItemTemplate>
            </asp:TemplateField>
            <%-----------------------------------------------------------------------------------------------------------------%>
            <asp:TemplateField HeaderText="IDS / IPS" SortExpression="IDS_IPS">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList11" runat="server" SelectedIndex='<%# Bind("IDS_IPS") %>'>
                        <asp:ListItem>N/A</asp:ListItem>
                        <asp:ListItem>Gap</asp:ListItem>
                        <asp:ListItem>Upd</asp:ListItem>
                        <asp:ListItem>Current</asp:ListItem>
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:DropDownList ID="DropDownList12" runat="server" SelectedIndex='<%# Bind("IDS_IPS") %>'>
                        <asp:ListItem>N/A</asp:ListItem>
                        <asp:ListItem>Gap</asp:ListItem>
                        <asp:ListItem>Upd</asp:ListItem>
                        <asp:ListItem>Current</asp:ListItem>
                    </asp:DropDownList>
                </ItemTemplate>
            </asp:TemplateField>
            <%-----------------------------------------------------------------------------------------------------------------%>
            <asp:TemplateField HeaderText="Network" SortExpression="Network">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList13" runat="server" SelectedIndex='<%# Bind("Network") %>'>
                        <asp:ListItem>N/A</asp:ListItem>
                        <asp:ListItem>Gap</asp:ListItem>
                        <asp:ListItem>Upd</asp:ListItem>
                        <asp:ListItem>Current</asp:ListItem>
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:DropDownList ID="DropDownList14" runat="server" SelectedIndex='<%# Bind("Network") %>'>
                        <asp:ListItem>N/A</asp:ListItem>
                        <asp:ListItem>Gap</asp:ListItem>
                        <asp:ListItem>Upd</asp:ListItem>
                        <asp:ListItem>Current</asp:ListItem>
                    </asp:DropDownList>
                </ItemTemplate>
            </asp:TemplateField>
            <%-----------------------------------------------------------------------------------------------------------------%>
            <asp:TemplateField HeaderText="<center>Other</center>" SortExpression="Other">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList15" runat="server" SelectedIndex='<%# Bind("Other") %>'>
                        <asp:ListItem>N/A</asp:ListItem>
                        <asp:ListItem>Gap</asp:ListItem>
                        <asp:ListItem>Upd</asp:ListItem>
                        <asp:ListItem>Current</asp:ListItem>
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:DropDownList ID="DropDownList16" runat="server" SelectedIndex='<%# Bind("Other") %>'>
                        <asp:ListItem>N/A</asp:ListItem>
                        <asp:ListItem>Gap</asp:ListItem>
                        <asp:ListItem>Upd</asp:ListItem>
                        <asp:ListItem>Current</asp:ListItem>
                    </asp:DropDownList>
                </ItemTemplate>
            </asp:TemplateField>
            <%-----------------------------------------------------------------------------------------------------------------%>
        </Columns>
        <HeaderStyle BackColor="#0066FF" ForeColor="#CCFFFF" HorizontalAlign="Center" />
    </asp:GridView>
    <asp:SqlDataSource ID="GapDocDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ARFSConnectionString %>" SelectCommand="SELECT [DocID], [DElement_Sub], [Doc_Name], [ENote], [Doc_Section], [Windows_C], [Windows_G], [Windows_U], [UNIX], [Mainframe], [IDS_IPS], [Network], [Other], [NotApply] FROM [GETT_DocGaps] WHERE ([ARSDocTag] = @ARSDocTag)" DeleteCommand="DELETE FROM GETT_DocGaps WHERE (DElement_Sub = @DElement_Sub) AND (ARSDocTag = @ARSDocTag)" InsertCommand="INSERT INTO GETT_DocGaps(ARSDocTag, DElement_Sub, Doc_Name) VALUES (@ARSDocTag, @DElement_Sub, @Doc_Name)" UpdateCommand="UPDATE GETT_DocGaps SET Doc_Name = @Doc_Name, ENote = @ENote, Doc_Section = @Doc_Section, Windows_C = @Windows_C, Windows_G = @Windows_G, Windows_U = @Windows_U, UNIX = @UNIX, Mainframe = @Mainframe, IDS_IPS = @IDS_IPS, Network = @Network, Other = @Other, NotApply = @NotApply WHERE (DocID = @DocID)">
        <DeleteParameters>
            <asp:Parameter Name="DElement_Sub"></asp:Parameter>
            <asp:Parameter Name="ARSDocTag"></asp:Parameter>
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="ARSDocTag"></asp:Parameter>
            <asp:Parameter Name="DElement_Sub"></asp:Parameter>
            <asp:Parameter Name="Doc_Name"></asp:Parameter>
        </InsertParameters>
        <SelectParameters>
            <asp:SessionParameter Name="ARSDocTag" SessionField="ArticleFocus" Type="String" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="Doc_Name" />
            <asp:Parameter Name="ENote"></asp:Parameter>
            <asp:Parameter Name="Doc_Section"></asp:Parameter>
            <asp:Parameter Name="Windows_C"></asp:Parameter>
            <asp:Parameter Name="Windows_G"></asp:Parameter>
            <asp:Parameter Name="Windows_U"></asp:Parameter>
            <asp:Parameter Name="UNIX"></asp:Parameter>
            <asp:Parameter Name="Mainframe"></asp:Parameter>
            <asp:Parameter Name="IDS_IPS"></asp:Parameter>
            <asp:Parameter Name="Network"></asp:Parameter>
            <asp:Parameter Name="Other"></asp:Parameter>
            <asp:Parameter Name="NotApply"></asp:Parameter>
            <asp:Parameter Name="DocID"></asp:Parameter>
        </UpdateParameters>
    </asp:SqlDataSource>
</asp:Content>


Here is the Code behind in VB:
VB
Public Class GapDocument
    Inherits Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        FamilyLabel.Text = Session("FamilyFocus")
        ArticleLabel.Text = Session("ArticleFocus")
        DocumentTitleLabel.Text = Session("GapDocument")

    End Sub
    Protected Sub GridView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GridView1.SelectedIndexChanged
        Dim url As String = "Article.aspx"
        Dim sb As New StringBuilder()
        sb.Append("<script type = 'text/javascript'>")
        sb.Append("window.open('")
        sb.Append(url)
        sb.Append("');")
        sb.Append("</script>")
        ClientScript.RegisterStartupScript([GetType](), "script", sb.ToString())
    End Sub

    Protected Sub GridView1_RowUpdating(sender As Object, e As GridViewUpdateEventArgs) Handles GridView1.RowUpdating
        'Get the Edit row
        'Dim row As GridViewRow = GridView1.Rows(e.RowIndex)
        'Dim ddl As Label = row.FindControl("DocID")

        If True Then
            Try
                'Session("DocId") = row.Cells(0).ToString
                GapDocDataSource.Update()
            Catch
            End Try
        End If
    End Sub

End Class
Posted
Updated 18-Nov-15 8:10am
v2
Comments
ZurdoDev 17-Nov-15 20:09pm
   
What is the actual problem? What is the error?
George Jonsson 17-Nov-15 22:35pm
   
What I usually do in this situation is to start from scratch, rethink the design and add the features I want one by one.
It sucks and it is a bit of effort, but better than banging your head against the wall.
And in the end you can compare the new code with the old and maybe see what went wrong.

1 solution

RyamDev,
That's the problem there are no error to work from. None what so ever. If there were then there would be something to work in Debug. But because it isn't casting anything off and the data looked okay I was lost.

All,
I did get past this one issue. I will be posting a simpler question here shortly and closing this one out here with what I came up with as I did manage to get the sub functioning correctly. (just not the function)

Here is what was done:

First I had to add a public variable to the code behind so just after the opening lines I entered in:
Dim ident As String = ""

Then the sub which processed the update was modified so as to capture the row properly and then the unique identifier for the row 'DocID' and put that in a session variable named the same. I tested the update method configured with and without using the session var "DocID" but in both cases that has failed to update. However, because the issue for which I opened this question has now been resolved I'm going to close this question and repost a simpler question regarding the update issue that might get some better focus from the group.

Here is the new sub as it is working now and it does function as intended pulling the data from the gridview1:
C#
Protected Sub GridView1_RowUpdating(sender As Object, e As GridViewUpdateEventArgs) Handles GridView1.RowUpdating
  Try
    Dim row As GridViewRow = GridView1.Rows(e.RowIndex)
    ident = row.Cells(3).Text
    Session("DocId") = ident
  Catch
  End Try
End Sub


Thanks,
Ken...
   

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