Solved

Updating a gridview populated with a datatable

Posted on 2007-03-20
6
803 Views
Last Modified: 2012-05-05
I have a page that has the gridview below. I am populating this gridview with a dataTable. I run a stored procedure
 that performs a search. I will like to update any row once my result is displayed in the grid.
 How can I do that?
 Here is my gridview below:


td>
    <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateEditButton="true" DataKeyNames="staffid" >
         <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
         <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
         <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
         <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
         <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
         <AlternatingRowStyle BackColor="White" />
    </asp:GridView>
         <asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource>
</td>


  Here is my asp.net code
 
           SqlDataAdapter da = new SqlDataAdapter("SamplePerformSearch", cn);
            da.SelectCommand.CommandType = CommandType.StoredProcedure;
            da.SelectCommand.Parameters.Add(new SqlParameter("@StaffID", SqlDbType.VarChar, 4));
            da.SelectCommand.Parameters["@StaffID"].Value = txtStaffID.Text;

            da.SelectCommand.Parameters.Add(new SqlParameter("@LastName", SqlDbType.VarChar, 30));
            da.SelectCommand.Parameters["@LastName"].Value = txtLastName.Text;

            da.SelectCommand.Parameters.Add(new SqlParameter("@FirstName", SqlDbType.VarChar, 30));
            da.SelectCommand.Parameters["@FirstName"].Value = txtFirstName.Text;

            DataTable dt = new DataTable();
            da.Fill(dt);
            GridView1.DataSource = dt;
            GridView1.DataBind();
   
  my search result only returns staffid, lastname, firstname, address.
  I want to be able to Edit and update lastname,firstname and address from the gridview.

Thanks
0
Comment
Question by:Sirdots
  • 2
6 Comments
 
LVL 11

Accepted Solution

by:
G0ggy earned 500 total points
ID: 18757427
Have a read of 4Guys article on the datagrid, it details everything you want to do over the 18 parts:

http://aspnet.4guysfromrolla.com/articles/040502-1.aspx
0
 

Author Comment

by:Sirdots
ID: 18757550
Thanks Goggy.  I am using a gridview and not a datagrid. [visual studio 2005]
0
 
LVL 11

Expert Comment

by:G0ggy
ID: 18757600
I know mate, but a lot of the properties and events are the same/similar, and their article is comprehensive, it should help you.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

920 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

15 Experts available now in Live!

Get 1:1 Help Now