Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Newbie, adding a row to Gridview in VB

Thread Tools

Newbie, adding a row to Gridview in VB

Posts: n/a
Can anyone help me or point me in the right direction, I'm running Win XP
Pro SP2, VS2005 Team, .Net Framework
2.0 and SQL Server2005.

I want to put a command button in the footer that adds a new row in my
gridview control, so I can insert a new record in the table, my control code
is below.

Best Regards

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default3.aspx.vb"
Inherits="Default3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<html xmlns="" >

<head runat="server">

<title>Untitled Page</title>



<form id="form1" runat="server">


<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:NwindConnectionString %>"

SelectCommand="SELECT p.ProductID, p.ProductName, p.CategoryID,
c.CategoryName FROM Products p inner join Categories c on p.CategoryID =

UpdateCommand="Update Products Set ProductID=@ProductID,
ProductName=@ProductName, CategoryID=@CategoryID where ProductID=@ProductID"

deletecommand="delete from products where productid=@productid">


<asparameter Name="productID" Type="Int32" />



<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$
ConnectionStrings:NwindConnectionString %>"

SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Categories]">



<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" CellPadding="4" ForeColor="#333333"
GridLines="None" AllowPaging="True" DataKeyNames="productID" >


<asp:CommandField ButtonType="Image" CancelImageUrl="~/Images/Cancel.gif"

ShowEditButton="True" UpdateImageUrl="~/Images/Update.gif"
DeleteImageUrl="~/Images/waste-trash.gif" ShowDeleteButton="True" />

<asp:TemplateField SortExpression="ProductID">


<asp:Label ID="TextBox1" runat="server" Text='<%# Bind("ProductID")%>'



<asp:Label ID="Label2" runat="server" Text='<%# Bind("ProductID") %>'



<asp:BoundField DataField="ProductName" HeaderText="ProductName"
SortExpression="ProductName" />

<asp:TemplateField HeaderText="CategoryID" SortExpression="CategoryID">


<aspropDownList ID="DropDownList1" runat="server"

DataTextField="CategoryName" DataValueField="CategoryID" SelectedValue='<%#
Bind("CategoryID") %>' >




<asp:Label ID="Label1" runat="server" Text='<%# Bind("CategoryName")




<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />

<SelectedRowStyle BackColor="#D1DDF1" ForeColor="#333333" Font-Bold="True"

<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center"

<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />

<AlternatingRowStyle BackColor="White" />

<RowStyle BackColor="#EFF3FB" />

<EditRowStyle BackColor="#2461BF" />





Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Gridview row databound event - can't get past the 1st row of gridview ASP .Net 5 10-13-2006 09:37 PM
GridView nested in DataList - refreshing corresponding DataList row after updating GridView row H5N1 ASP .Net 0 04-26-2006 11:41 PM
ok I can do a totals row but how about a percentage row after each data row D ASP .Net Datagrid Control 0 05-23-2005 04:10 PM
Highlight the row and click anywhere to select a row in a GridView Fernando Lopes ASP .Net 0 04-28-2005 12:24 PM
My addnew row button is only adding one row? Luis Esteban Valencia ASP .Net 0 03-23-2005 04:03 PM