Solved

Updating a gridview populated with a datatable

Posted on 2007-03-20
6
805 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
RLDC Reporting in Visual studio 11 30
defining NULL or 0 10 44
VS 2015 is giving [No relevant source lines] 2 26
using CK editor in iframes 5 16
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

840 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