Problem with edit

Discussion in 'ASP .Net Datagrid Control' started by Jonas Karlsson, Aug 27, 2003.

  1. I have a edit problem with my DataGrid. The Update and Cancel buttons won't
    show when I press Edit. What can be wrong?! The cod is to be included in a
    Sharepoint WebPart therefor I'm not using any ordinary <asp:datagrid> tags.
    The control is rendered using MyDataGrid.RenderControl()

    I also have a problem with the EditCommand event. When building my control
    after setting my event handler i get this error:

    Method 'Northwind.CustomerRowProvider.DataGrid1_EditCommand(object,
    System.Web.UI.WebControls.DataGridCommandEventArgs)' does not match delegate
    'void System.EventHandler(object, System.EventArgs)'


    My code:

    SqlConnection myConnection = new SqlConnection("Integrated
    Security=SSPI;Persist Security Info=False;Initial Catalog=TimeReport;Data
    Source=(local);");
    myConnection.Open();
    SqlDataAdapter myCommand = new SqlDataAdapter("select * from Customer",
    myConnection);
    DataSet ds = new DataSet();
    myCommand.Fill(ds, "Customer");
    MyDataGrid = new DataGrid();
    MyDataGrid.AutoGenerateColumns = false;
    MyDataGrid.DataSource=ds.Tables["Customer"].DefaultView;
    MyDataGrid.EditCommand += new
    System.EventHandler(this.DataGrid1_EditCommand);



    EditCommandColumn c = new EditCommandColumn();
    c.EditText = "Edit";
    c.UpdateText ="Update";
    c.CancelText = "Cancel";
    c.HeaderText = "";
    MyDataGrid.Columns.Add(c);

    MyDataGrid.DataBind();

    myConnection.Close();



    private void DataGrid1_EditCommand(object source, DataGridCommandEventArgs
    e)
    {
    MyDataGrid.EditItemIndex = e.Item.ItemIndex;
    MyDataGrid.DataBind();
    }



    /Jonas Karlsson
    Jonas Karlsson, Aug 27, 2003
    #1
    1. Advertising

  2. I solved this problem myself, but I am surprised that I couldn't find the
    answer here...

    The trick is to use
    GridDays.EditCommand += new DataGridCommandEventHandler(GridDays_Edit);

    "Jonas Karlsson" <> wrote in message
    news:...
    > I have a edit problem with my DataGrid. The Update and Cancel buttons

    won't
    > show when I press Edit. What can be wrong?! The cod is to be included in a
    > Sharepoint WebPart therefor I'm not using any ordinary <asp:datagrid>

    tags.
    > The control is rendered using MyDataGrid.RenderControl()
    >
    > I also have a problem with the EditCommand event. When building my control
    > after setting my event handler i get this error:
    >
    > Method 'Northwind.CustomerRowProvider.DataGrid1_EditCommand(object,
    > System.Web.UI.WebControls.DataGridCommandEventArgs)' does not match

    delegate
    > 'void System.EventHandler(object, System.EventArgs)'
    >
    >
    > My code:
    >
    > SqlConnection myConnection = new SqlConnection("Integrated
    > Security=SSPI;Persist Security Info=False;Initial Catalog=TimeReport;Data
    > Source=(local);");
    > myConnection.Open();
    > SqlDataAdapter myCommand = new SqlDataAdapter("select * from Customer",
    > myConnection);
    > DataSet ds = new DataSet();
    > myCommand.Fill(ds, "Customer");
    > MyDataGrid = new DataGrid();
    > MyDataGrid.AutoGenerateColumns = false;
    > MyDataGrid.DataSource=ds.Tables["Customer"].DefaultView;
    > MyDataGrid.EditCommand += new
    > System.EventHandler(this.DataGrid1_EditCommand);
    >
    >
    >
    > EditCommandColumn c = new EditCommandColumn();
    > c.EditText = "Edit";
    > c.UpdateText ="Update";
    > c.CancelText = "Cancel";
    > c.HeaderText = "";
    > MyDataGrid.Columns.Add(c);
    >
    > MyDataGrid.DataBind();
    >
    > myConnection.Close();
    >
    >
    >
    > private void DataGrid1_EditCommand(object source, DataGridCommandEventArgs
    > e)
    > {
    > MyDataGrid.EditItemIndex = e.Item.ItemIndex;
    > MyDataGrid.DataBind();
    > }
    >
    >
    >
    > /Jonas Karlsson
    >
    >
    >
    >
    >
    Jonas Karlsson, Aug 27, 2003
    #2
    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. San Diego Guy
    Replies:
    0
    Views:
    531
    San Diego Guy
    Aug 7, 2003
  2. Schultz
    Replies:
    3
    Views:
    544
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Feb 14, 2005
  3. =?Utf-8?B?a2Vu?=
    Replies:
    1
    Views:
    10,309
    Wiktor Zychla [C# MVP]
    Jan 23, 2006
  4. Sharon McCarty
    Replies:
    0
    Views:
    240
    Sharon McCarty
    Nov 24, 2004
  5. Frank Kurka
    Replies:
    8
    Views:
    288
Loading...

Share This Page