Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Gridview in c# not updating

Posted on 2010-08-30
1
Medium Priority
?
309 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
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Screencast - Getting to Know the Pipeline

927 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