473,471 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Unable to update in gridview

Hi,

I have a web user control which includes a gridview and a sqldatasource. It
also has a property called TableName which is used to populate the gridview.
However, i'm running into a problem where i can select and delete row but i
cannot update a row.

Here is the code in the usercontrol

protected void Page_Load(object sender, EventArgs e)
{

if (!Page.IsPostBack)
{
if (Roles.IsUserInRole("Management"))
{
GridView1.AutoGenerateEditButton = true;
GridView1.AutoGenerateDeleteButton = true;
}
}
SqlDataSource1.ConnectionString = Session["ConnStr"].ToString();
//SqlDataSource1.SelectCommand = "SELECT [Studio], [code], [Name]
FROM [Studio]";
//SqlDataSource1.UpdateCommand = "Update Studio set [code] = @Code,
[Name] = @Name where [Studio] = @Studio";
//SqlDataSource1.DeleteCommand = "Delete from Studio where [Studio]
= @Studio";
SqlDataSource1.DeleteCommand = "Delete from " + tablename + " where
[" + tablename + "] = @" + tablename;
SqlDataSource1.SelectCommand = "SELECT [" + tablename + "], [code],
[Name] FROM [" + tablename + "]";
SqlDataSource1.UpdateCommand = "Update [" + tablename + "] set
[code] = @Code, [Name] = @Name where [" + tablename + "] = @" + tablename;
SqlDataSource1.DataBind();

string[] arListType = new string[1];
arListType[0] = tablename;
GridView1.DataKeyNames = arListType;
BoundField bf = new BoundField();
bf.DataField = tablename;
bf.HeaderText = tablename;
//bf.Visible = false;
bf.ReadOnly = true;

BoundField bf2 = new BoundField();
bf2.DataField = "Code";
bf2.HeaderText = "Code";

BoundField bf3 = new BoundField();
bf3.DataField = "Name";
bf3.HeaderText = "Name";

GridView1.Columns.Clear();
GridView1.Columns.Add(bf);
GridView1.Columns.Add(bf2);
GridView1.Columns.Add(bf3);

GridView1.DataBind();

}

Does anyone has any idea why and how to fix it?

Thanks!

Jun 16 '06 #1
0 1379

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: mesut | last post by:
Hi there, I've a question. I would like to create a global update button to update all changed records gridview. e.g. A gridview contains 5 columns an 2 of the columns can be updated by the...
1
by: sheenaa | last post by:
Hello Members, I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005. What i have used on forms :: ? On my first form i have used some...
1
by: Evan M. | last post by:
Here's my GridView and my SqlDataSource <asp:GridView ID="ContactHistoryGrid" runat="server" AutoGenerateColumns="False" DataSourceID="ContactHistoryDS" DataKeyNames="JobHistoryID"...
1
by: gabe | last post by:
How do you call a client side javascript callback method after an update panel has posted back to the server? I have two update panels (A + B) with a gridview in each panel. GridView B has a...
4
by: tim.cavins | last post by:
I have a GridView populated by an ObjectDataSource. I am having issues passing the parameters to the objectdatasource. I have verified that the method is being called but none of the parameters...
5
by: Luqman | last post by:
I added new rows to the GridView with the following code. I am using SqlDataSource and Sql Server 2000 Northwind Database Customers table. Dim sqlarg As New DataSourceSelectArguments Dim dv...
2
by: Looch | last post by:
Hi, I'm filling a GridView with a simple sproc select statement. I'm trying to use the Update tab to create an update statement and using the following: Update Shipping_Requests Set Shipped...
1
by: sana krishna | last post by:
Hai, Pls anyone help me........................... I am using ASP.NET(C#). I want to display the data in a gridview and make the gridview to become editable and insert and delete. But i can't...
11
by: SAL | last post by:
Hello, I have a Gridview control (.net 2.0) that I'm having trouble getting the Update button to fire any kind of event or preforming the update. The datatable is based on a join so I don't know...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.