HighTechTalks DotNet Forums  

Unable to update in gridview

ASP.net Data Grid Control microsoft.public.dotnet.framework.aspnet.datagridcontrol


Discuss Unable to update in gridview in the ASP.net Data Grid Control forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Terence
 
Posts: n/a

Default Unable to update in gridview - 06-16-2006 , 02:37 PM






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!


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.