Solved

updating a gridview in asp .net

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Any Third party toll for Integrating chat system on ASP.NET ? 2 42
Not showing page correctly 3 40
Reset asp.net login password 4 42
tutorial for ebay api 3 32
Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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