1

I'm using asp.net with c# code behind, and all I want to do is have a gridview+sqldatasource that I can manipulate at runtime and for whatever reason the buttons don't work. I have a login page that passes the username over via querystring and then this page is ONLY a gridview right now. When I click the delete button it immediately takes me to the login page with the fields blank again. For testing purposes I'm using just the delete button but I've had the same experience with the edit button as well, it never does the "update mode" like it seems it should.

        <asp:GridView DataKeyNames="ID" ID="GridView1" runat="server" DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True" PageSize="8" OnRowDataBound="GridView1_RowDataBound">
            <Columns>
                <asp:CommandField ShowDeleteButton="True" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString='<%$ ConnectionStrings:WebMasterLogConnectionString2 %>'
            SelectCommand="SELECT * FROM [WebmasterLogs] WHERE ([Username] = @Username) ORDER BY [ID]"
            ConflictDetection="CompareAllValues" 
            DeleteCommand="DELETE FROM [WebmasterLogs] WHERE [ID] = @original_ID" 
            OldValuesParameterFormatString="original_{0}" >
            <DeleteParameters>
                <asp:Parameter Name="original_ID" Type="Int32" />
            </DeleteParameters>
            <SelectParameters>
                <asp:Parameter Name="ID" Type="Int32" />
                <asp:QueryStringParameter Name="Username" QueryStringField="Username" Type="String" />
                <asp:Parameter Name="LogEntryDate" Type="DateTime" />
                <asp:Parameter Name="TimeSpent" Type="String" />
                <asp:Parameter Name="Description" Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>

Web Config:

<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <appSettings>
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
  </appSettings>
  <connectionStrings>
    <add name="WebMasterLogConnectionString" connectionString="Data Source=35sql;Initial Catalog=WebMasterLog;Persist Security Info=False;User ID=*****;Password=*********"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

2 Answers 2

2

There is NO need to define the Delete parameter here since the @original_ID parameter will be automatically submitted by the data control because of the setting OldValuesParameterFormatString="original_{0}".

Therefore the parameter @original_ID will have the appropriate ID value already.


The <asp:Parameter ... /> declaration is used only when you want to set the parameter programmatically.

Sign up to request clarification or add additional context in comments.

5 Comments

Ok, that was actually auto-generated by Visual studio so I didn't question it. I removed that and it hasn't changed my issue at all.
Is there any exception thrown ?? any thing you have in your Logs ?
Literally no indication of any error, just kicks me back to my login page instantly.
Any authentication/session mechanish implemented ? check settings in web.config too
Added my web config, but nothing stands out to me there as to why it would behave that way. Throwing an exception I could see, but I get nothing.
0

Figured this out. I hadn't defined the click events properly for editing/updating/deleting.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.