Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Gridview in c# not updating

Posted on 2010-08-30
1
Medium Priority
?
308 Views
Last Modified: 2012-06-27
Pretty simple though but not working :S

 i have a gridview bound to sqldatasource with update command but for some reasons on updating a row does not seem to work. Attaching my code in code part.
Thanks
<asp:GridView ID="gvStudentPersonal" runat="server" DataSourceID="ds_StudentDetail"
                    AutoGenerateColumns="False" DataKeyNames="MatricNo" AutoGenerateEditButton="True">
                    <Columns>
                        <asp:BoundField ReadOnly="true" HeaderText="MatricNo" DataField="MatricNo" SortExpression="MatricNo" />
                        <asp:BoundField HeaderText="Email" DataField="Email" />
                        <asp:BoundField HeaderText="DateOfBirth" DataField="DateOfBirth" />
                        <asp:BoundField HeaderText="Active" DataField="Active" />
                        <asp:BoundField HeaderText="Repeating" DataField="Repeating" />
                    </Columns>
                </asp:GridView>


 <asp:SqlDataSource ID="ds_StudentDetail" runat="server" ConnectionString="<%$ ConnectionStrings:EnterpriseValeConnectionString %>"
        SelectCommand="SELECT [MatricNo], [Email], Convert(varchar(50),[DateOfBirth],104) DateOfBirth,  [Active], [Repeating] FROM [Student] WHERE ([MatricNo] = @MatricNo)"
        UpdateCommand="Update Student Set Email=@Email,DateOfBirth=@DateOfBirth,Active=@Active, Repeating=@Repeating where MatricNo=@MatricNo">
        <SelectParameters>
            <asp:SessionParameter DefaultValue="0" Name="MatricNo" SessionField="MatricNo" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>

Open in new window

0
Comment
Question by:mmalik15
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 22

Accepted Solution

by:
Om Prakash earned 2000 total points
ID: 33556873
you can add OnUpdated="OnUpdHandler" handler in SqlDataSource to see data is populated correctly..

example


<asp:Label
          id="Label1"
          runat="server">
      </asp:Label>

 <asp:SqlDataSource  ..other parameters..
 	        	OnUpdated="OnUpdHandler">

code behind

 Sub OnDSUpdatedHandler(ByVal source As Object, ByVal e As SqlDataSourceStatusEventArgs)
    If e.AffectedRows > 0 Then 'set a status label 
        Label1.Text = "data modified successfully.."
    Else 
        Label1.Text = "No data updated!"
    End If
 End Sub 

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

719 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