Solved

updating a gridview in asp .net

Posted on 2013-01-11
1
457 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

861 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now