GridView Update Not Firing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • spamguy
    New Member
    • Sep 2007
    • 42

    GridView Update Not Firing

    I am working porting ugly .NET 1.1 DataGrids to 2.0 GridViews. The GridView fills correctly via SqlDataSource. When I click Edit -> [make a field change] -> Update, the page refreshes but the update command clearly never fired. (Putting stuff in the GridView's OnRowUpdating function proves this.) The row also remains in edit mode.

    The code:

    [code=html]<asp:SqlDataSou rce ID="dsMyReports " runat="server"
    ConnectionStrin g="<%$ ConnectionStrin gs:vortex2devCo nnectionString %>"
    SelectCommand=" SELECT [ID], [Name], [Description] FROM [Report] WHERE (([IsPublic] = @IsPublic) AND ([OwnedByUserID] = @userID))"
    OnSelecting="ds MyReports_Selec ting"
    DeleteCommand=" DELETE FROM Report WHERE ID = @reportID"
    UpdateCommand=" UPDATE Report SET Name = @Name, Description = @Description WHERE ID = @ID">
    <SelectParamete rs>
    <asp:Paramete r DefaultValue="0 " Name="IsPublic" Type="Int32" />
    <asp:Paramete r DefaultValue="" Name="userID" Type="Int32" />
    </SelectParameter s>
    <DeleteParamete rs>
    <asp:Paramete r Name="reportID" />
    </DeleteParameter s>
    <UpdateParamete rs>
    <asp:Paramete r Name="Name" />
    <asp:Paramete r Name="Descripti on" />
    <asp:Paramete r Name="ID" />
    </UpdateParameter s>
    </asp:SqlDataSour ce>

    <asp:GridView ID="myReportsGr id" runat="server" AutoGenerateCol umns="False" DataSourceID="d sMyReports" DataKeyNames="I D">
    <Columns>
    <asp:BoundFie ld DataField="Name " HeaderText="Nam e" SortExpression= "Name" />
    <asp:BoundFie ld DataField="Desc ription" HeaderText="Des cription" SortExpression= "Descriptio n" />
    <asp:CommandFie ld ControlStyle-Width="16px" ButtonType="Ima ge" EditImageUrl="~/images/edit_icon2.gif" ShowEditButton= "true" />
    </Columns>
    </asp:GridView>[/code]

    Thanks!
  • bhupinder
    New Member
    • Feb 2009
    • 32

    #2
    Added [code] tags

    We can update easily using sqldatasource
    but you have to pass parameters same name of the column

    like langid=@langid if we change,
    langid=@id it will not work its better you must use rowediting event rather than
    sqldatasource
    Code:
     <asp:GridView ID="gvdata" runat="server" AutoGenerateColumns="False" DataKeyNames="locationID"
            DataSourceID="SqlDataSource1">
            <Columns>
                <asp:CommandField ShowEditButton="True" />
                <asp:BoundField DataField="locationID" HeaderText="locationID" InsertVisible="False"
                    ReadOnly="True" SortExpression="locationID" />
                <asp:BoundField DataField="locationName" HeaderText="locationName" SortExpression="locationName" />
                <asp:BoundField DataField="langID" HeaderText="langID" SortExpression="langID" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MWCConnectionString %>"
            SelectCommand="SELECT [locationID], [locationName], [langID] FROM [tbl_locationInfo]"
            UpdateCommand="update tbl_locationinfo set locationName=@locationName ,langID=@langID where locationid=@locationid">
            <UpdateParameters>
                <asp:Parameter Name="locationName" />
                <asp:Parameter Name="langID" />
                <asp:Parameter Name="locationid" />
            </UpdateParameters>
        </asp:SqlDataSource>

    Comment

    Working...