Solved

updating a gridview in asp .net

Posted on 2013-01-11
1
459 Views
Last Modified: 2013-01-13
I have the below code for a gridView.  I want to be able to update the data on the gridview. Im using the function below. My problem is that for the values
for newValues("GamesPlayed")   and  newValues("GamesWon") that I am getting in the GridView1_RowUpdating Sub  are not the new values that I am typing on the textboxes TextGamesPlayed and TextGamesWon. The values Im getting are the old values that were there before on that row.  Anybody knows why this is happening or what am I missing?  thanks


<asp:GridView ID="GridView1" runat="server" CellPadding="3" ForeColor="Black" AutoGenerateColumns="false"
            GridLines="Vertical" BackColor="White" BorderColor="#999999"
            BorderStyle="Solid" BorderWidth="1px" EnableModelValidation="True" onrowupdating="GridView1_RowUpdating" onrowediting="GridView1_RowEditing">
            <AlternatingRowStyle BackColor="#CCCCCC" ForeColor="#DC143C" />
            <Columns>
            <asp:templatefield>
                                <itemtemplate>
                                        <asp:linkbutton ForeColor="#C60000" id="btnSelect" runat="server" commandname="Select" text="Select" />
                                        <asp:linkbutton ForeColor="#C60000" id="btnEdit" runat="server" commandname="Edit" text="Edit" />
                                        <asp:linkbutton ForeColor="#C60000" id="btnDelete" runat="server" commandname="Delete" text="Delete" />
                                </itemtemplate>
                                <edititemtemplate>
                                        <asp:linkbutton ForeColor="#C60000" id="btnUpdate" runat="server" commandname="Update" text="Update" />
                                        <asp:linkbutton ForeColor="#C60000" id="btnCancel" runat="server" commandname="Cancel" text="Cancel" />
                                </edititemtemplate>
                                <footertemplate>
                                        <asp:linkbutton ForeColor="#C60000" id="btnInsert" runat="server" commandname="Insert" text="Insert" />
                                </footertemplate>
                        </asp:templatefield>
            <%--<asp:BoundField ReadOnly="True" HeaderText=" Pl " 
                  InsertVisible="False" DataField="GamesPlayed"
                    SortExpression="GamesPlayed" HeaderStyle-Width="50">
                    <ItemStyle HorizontalAlign="Center"></ItemStyle>  
                </asp:BoundField>--%>
                 <asp:BoundField ReadOnly="True" HeaderText=" ID " 
                  InsertVisible="False" DataField="TeamRecordId"
                    SortExpression="TeamRecordId" HeaderStyle-Width="50">
                    <ItemStyle HorizontalAlign="Center"></ItemStyle>
                </asp:BoundField>
                <asp:templatefield headertext="Pl" sortexpression="GamesPlayed" InsertVisible="False"
                     HeaderStyle-Width="50">
                                <itemtemplate>
                                        <%# Eval("GamesPlayed")%>
                                </itemtemplate>
                                <edititemtemplate>
                                        <asp:textbox id="TextGamesPlayed" runat="server" text='<%# Bind("GamesPlayed") %>' />
                                </edititemtemplate>
                                <footertemplate>
                                        <asp:textbox id="TextGamesPlayed" runat="server" />
                                </footertemplate>
                        </asp:templatefield>
                        <asp:templatefield headertext="W" sortexpression="GamesWon" InsertVisible="False"
                     HeaderStyle-Width="50">
                                <itemtemplate>
                                        <%# Eval("GamesWon")%>
                                </itemtemplate>
                                <edititemtemplate>
                                        <asp:textbox id="TextGamesWon" runat="server" text='<%# Bind("GamesWon") %>' />
                                </edititemtemplate>
                                <footertemplate>
                                        <asp:textbox id="TextGamesWon" runat="server" />
                                </footertemplate>
                        </asp:templatefield>
                                   
            </Columns>
       
            <FooterStyle BackColor="#CCCCCC" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#C60000" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#999999" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="#333333" />
            <%--<SortedAscendingCellStyle BackColor="#E9E7E2" />
            <SortedAscendingHeaderStyle BackColor="#506C8C" />
            <SortedDescendingCellStyle BackColor="#FFFDF8" />
            <SortedDescendingHeaderStyle BackColor="#6F8DAE" />--%>
       
        </asp:GridView>


Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
        Dim objRecordBSL As New TeamRecordBSL
        Dim objRecordDTO As New TeamRecordDTO
        Dim row As GridViewRow = GridView1.Rows(e.RowIndex)
        Dim newValues = Me.GetValues(row)
               
        objRecordDTO.GamesPlayed = newValues("GamesPlayed")
        objRecordDTO.TeamRecordId = newValues("TeamRecordId")
        objRecordDTO.GamesWon = newValues("GamesWon")  

        objRecordBSL.UpdateTeamRecord(objRecordDTO)
        GridView1.EditIndex = -1
        Me.SetData()
end sub

Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs)

        GridView1.EditIndex = e.NewEditIndex
        BindGrid()

End Sub
0
Comment
Question by:chicho12
1 Comment
 
LVL 23

Accepted Solution

by:
Roopesh Reddy earned 500 total points
ID: 38769407
Hi,

Check this thread - http://stackoverflow.com/questions/5000489/how-to-edit-and-update-row-values-in-grid-view

It's in C#, but the logic is same and you can easily convert it to VB!

Hope it helps u...
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question