Solved

updating a gridview in asp .net

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 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

11 Experts available now in Live!

Get 1:1 Help Now