Join the Stack Overflow Community
Stack Overflow is a community of 6.8 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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>
share|improve this question

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.

share|improve this answer
    
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. – Dylan Schmidt May 19 '15 at 12:31
    
Is there any exception thrown ?? any thing you have in your Logs ? – R.C May 19 '15 at 12:37
    
Literally no indication of any error, just kicks me back to my login page instantly. – Dylan Schmidt May 19 '15 at 12:51
    
Any authentication/session mechanish implemented ? check settings in web.config too – R.C May 19 '15 at 13:01
    
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. – Dylan Schmidt May 19 '15 at 14:07
up vote 0 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.