Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

updating a gridview in asp .net

Posted on 2013-01-11
1
Medium Priority
?
473 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 1500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Integration Management Part 2
Loops Section Overview
Suggested Courses

810 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