Unable to update in gridview

Discussion in 'ASP .Net Datagrid Control' started by Terence, Jun 16, 2006.

  1. Terence

    Terence Guest

    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!
    Terence, Jun 16, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?bWdvbnphbGVzMw==?=

    GridView Hierarchical View - Gridview in Gridview

    =?Utf-8?B?bWdvbnphbGVzMw==?=, May 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    17,961
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    May 9, 2006
  2. =?Utf-8?B?VGVyZW5jZQ==?=

    Unable to update in gridview

    =?Utf-8?B?VGVyZW5jZQ==?=, Jun 16, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    2,440
    =?Utf-8?B?VGVyZW5jZQ==?=
    Jun 16, 2006
  3. mesut
    Replies:
    0
    Views:
    663
    mesut
    Feb 19, 2007
  4. Evan M.
    Replies:
    1
    Views:
    1,198
    Evan M.
    Apr 18, 2007
  5. Jake Barnes
    Replies:
    6
    Views:
    390
    9.co.uk
    Feb 8, 2006
Loading...

Share This Page