Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Problem understanding how to make a dynamic GridView execute Update on SqlDataSource

Reply
Thread Tools

Problem understanding how to make a dynamic GridView execute Update on SqlDataSource

 
 
PeterKellner
Guest
Posts: n/a
 
      05-20-2006
I've create a very simple example that runs against the northwind
database that does not update the underlying database as I would
expect. I'm thinking there must be something I have to execute in
order to have the sqldatasource's Update actually run. The Updating
event does get called in the code below.

-thanks for any help on this. -Peter

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
protected GridView gv;

protected void Page_Load(object sender, EventArgs e)
{
gv = new GridView();

SqlDataSource sqlDataSource = new SqlDataSource();
sqlDataSource.ConnectionString = "Data Source=acer8200;Initial
Catalog=Northwind;Integrated Security=True";
sqlDataSource.SelectCommand = "SELECT [CategoryID],
[CategoryName] FROM [Categories]";

sqlDataSource.UpdateParameters.Clear();
sqlDataSource.UpdateParameters.Add("CategoryName",
TypeCode.String, string.Empty);
sqlDataSource.UpdateParameters.Add("CategoryI",
TypeCode.Int32, "0");

gv.DataSource = sqlDataSource;
gv.AutoGenerateEditButton = true;
gv.AutoGenerateDeleteButton = true;

gv.RowEditing += new GridViewEditEventHandler(gv_RowEditing);
gv.RowUpdating += new
GridViewUpdateEventHandler(gv_RowUpdating);
gv.RowUpdated += new
GridViewUpdatedEventHandler(gv_RowUpdated);
gv.RowDeleting += new
GridViewDeleteEventHandler(gv_RowDeleting);
gv.RowDeleted += new
GridViewDeletedEventHandler(gv_RowDeleted);
gv.RowCancelingEdit += new
GridViewCancelEditEventHandler(gv_RowCancelingEdit );


form1.Controls.Add(gv);
gv.DataBind();
}

void gv_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
gv.DataBind();
}

void gv_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
gv.EditIndex = -1;
gv.DataBind();
}

void gv_RowCancelingEdit(object sender,
GridViewCancelEditEventArgs e)
{
gv.EditIndex = -1;
gv.DataBind();
}

void gv_RowDeleted(object sender, GridViewDeletedEventArgs e)
{
gv.DataBind();
}

void gv_RowDeleting(object sender, GridViewDeleteEventArgs e)
{

}

void gv_RowEditing(object sender, GridViewEditEventArgs e)
{
gv.EditIndex = e.NewEditIndex;
gv.DataBind();
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Dynamic GridView Create With Edit</title>
</head>
<body>
<form id="form1" runat="server">

</form>
</body>
</html>
Peter Kellner
http://peterkellner.net
 
Reply With Quote
 
 
 
 
mou piya
Guest
Posts: n/a
 
      06-02-2006
Your article helped me a lot.Thanks for that.
I have one doubt.If i am using template fields in the gridview then
how to go?




*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
Reply

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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Problem Using SqlDataSource to automatically Update Value of item in Gridview Row Vaughn Haybittle ASP .Net Datagrid Control 0 04-02-2007 10:56 PM
Dynamic SQLDataSource with Gridview - Update Parameters OceanTragic ASP .Net 0 11-14-2006 12:01 PM
gridview and sqldatasource - refresh the gridview phil ASP .Net 2 11-14-2006 06:09 AM
Problem understanding how to create a dynamic GridView in C# PeterKellner ASP .Net Datagrid Control 2 05-19-2006 01:15 PM



Advertisments