Solved

Gridview in c# not updating

Posted on 2010-08-30
1
307 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 500 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

617 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