Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Updating a gridview populated with a datatable

Posted on 2007-03-20
6
Medium Priority
?
809 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
[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
  • 2
6 Comments
 
LVL 11

Accepted Solution

by:
G0ggy earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

688 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