|
|
|
|
|
|
|
Page Views :
|
316884
|
|
Downloads :
|
0
|
|
Rating :
|
Rate it
|
|
Level :
|
Beginner
|
|
The GridView was not designed to insert new rows, but there is a way to accomplish this with very little code.
- The first step is to add your data source and the DataView Grid. Ensure that your SqlDataSource statements or stored procedures in the:
- Select Command
- Insert Command
- My stored procedure just adds a new row and initializes to new or zero
- Update Command
- Delete Command
- Bind the DataView Grid to the SqlDataSource
- Edit the fields adding the following
- CommandField, enable the Edit and Delete, and disable the insert
- TemplateField

In the UI source code, I inserted the Item Template as follows:
<ItemTemplate>
<asp:LinkButton ID="lblNew" runat="server" CausesValidation="false"
CommandName="Insert"
Text="New" style="vertical-align: middle; text-align:
center" Font-Bold="False" ForeColor="Black"
Height="3px" Width="49px"
OnClick="GridViewInsert">
</asp:LinkButton>
</ItemTemplate>
Format the text as required, leaving the rest alone.
Text="New" style="vertical-align: middle; text-align: center" Font-Bold="False" ForeColor="Black" Height="3px" Width="49px"
Now your control looks as follows in design mode

The next step is to add a few lines of code so that there is only one New, when the web page is running
In the page where the control is running, insert the following code and change the names as required:
protected void GridViewInsert(object sender, EventArgs e) { SqlDataSource1.Insert(); } protected void GridView1_PreRender(object sender, EventArgs e) { for (int index = 0; index < GridView1.Rows.Count - 1; index++) {
GridView1.Rows[index].Cells[1].Controls[1].Visible = false;
}
}
Test and change the Cells[x] and Controls[x] as required
There will be training for the users, the User Sequence is:
- The user presses the New button
- The stored procedure inserts New or zero into each field
- The user now sees a new row at the bottom with New
- The user edits this new row, changing the values as required.
- The user presses the Update
The user pressed the Edit button

The user entered data and pressed the Update button

So how did this work, well in step 4 above, the OnClick="GridViewInsert" above calls the GridViewInsert(object sender, EventArgs e) code and executes the SqlDataSource1.Insert();, which inserts the data. Getting rid of all of the News in the DataView (except for the last one), happened in the GridView1_PreRender code.
|
|
Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post
Here.
|
|
|
|
|
Login
to add your contents and source code to this article
|
|
|
|
|
|
|
|
|
|
|
|
art_scott
Senior Lead Architect/Developer utilizing .NET C# 2.0/3.0, ASP.NET, SQL Server 2005, Reporting Server, .NET 3.0 Workflow, and Web Services. methodologies are Extreme Programming on the Microsoft Enterprise Library utilizing Model View Presenter (MVP). I utilize Visio Architecture to create UML which is then used to update the Team Visual Studio 2005. As the architect and senior/lead developer ensuring design standards, I also train my team on MVP development (WinForms and WebForms), pattern development, C# 2.0/3.0 development and coding as a working in the coding trenches while taking the time to meet with clients on a regular basis and ensuring that our developers are not only being taken care of but excited about our technology and methodologies.
|
|
|
|
|
|
|
|
|
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional
consulting company, our consultants are well-known experts in .NET and many of them
are MVPs, authors, and trainers. We specialize in Microsoft .NET development and
utilize Agile Development and Extreme Programming practices to provide fast pace
quick turnaround results. Our software development model is a mix of Agile Development,
traditional SDLC, and Waterfall models.
|
|
Click here to learn more about C# Consulting. |
|
|
|
|
|
|
|
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon.
Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees.
As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
|
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
|
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
|
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
|
|
|
|
|
|
|
|
|
|
|
|
|