Results 1 to 2 of 2

Thread: [RESOLVED] Having trouble using edit link to edit in datagrid....

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    28

    Resolved [RESOLVED] Having trouble using edit link to edit in datagrid....

    ok so i put in the edit/update/cancel links in the datagrid, i put in the events but nothing happens when i click on the links. im not getting any errors in my code, and triple checked my work. im sure im forgeting something but its beyond me, if you guys could help that would be AWESOME!




    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    namespace Database
    {
    /// <summary>
    /// Summary description for WebForm1.
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.Button Button1;
    protected System.Web.UI.WebControls.Button Button2;
    protected System.Web.UI.WebControls.Label Label1;
    protected System.Web.UI.WebControls.RadioButton RadioButton1;
    protected System.Web.UI.WebControls.RadioButton RadioButton2;
    protected System.Web.UI.WebControls.Label lblName;
    protected System.Web.UI.WebControls.TextBox TextBox2;
    protected System.Web.UI.WebControls.Button btnProcess;
    protected System.Web.UI.WebControls.TextBox TextBox1;
    protected System.Web.UI.WebControls.Button btnAddNew;
    protected System.Web.UI.WebControls.DataGrid DataGrid1;
    protected System.Web.UI.WebControls.Label lblTitle;

    private void Page_Load(object sender, System.EventArgs e)
    {
    SqlConnection odc = new SqlConnection("Data Source=TDS-JAREDPARKS;Database=Northwind;Integrated Security=SSPI;");
    string sc;
    sc = "SELECT CustomerID, ContactName FROM Customers";
    SqlDataAdapter da = new SqlDataAdapter(sc, odc);
    System.Data.DataSet ds = new DataSet();
    da.Fill(ds, "Customers");
    DataGrid1.DataSource = ds.Tables["Customers"];
    DataGrid1.DataBind();
    }
    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    //
    InitializeComponent();
    base.OnInit(e);
    }
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.btnProcess.Click += new System.EventHandler(this.btnProcess_Click);
    this.Load += new System.EventHandler(this.Page_Load);

    }
    #endregion


    private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    DataGrid1.EditItemIndex = e.Item.ItemIndex;
    DataGrid1.DataBind();
    }
    private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    DataGrid1.EditItemIndex = -1;
    DataGrid1.DataBind();
    }
    private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    string sc;
    sc = "SELECT Customers.CustomerID, Customers.ContactName FROM Customers";
    DataSet ds = new DataSet();
    SqlConnection odc = new SqlConnection("Data Source=TDS-JAREDPARKS;Database=Northwind;Integrated Security=SSPI;");
    SqlDataAdapter da = new SqlDataAdapter(sc, odc);
    SqlCommandBuilder cb = new SqlCommandBuilder();
    DataGrid1.DataSource = ds.Tables["Customers"];
    //
    string strCustomerID, strContactName;
    string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
    TextBox tb, tb2;
    tb = (TextBox)(e.Item.Cells[1].Controls[0]);
    strCustomerID = tb.Text;
    tb2 = (TextBox)(e.Item.Cells[2].Controls[0]);
    strContactName = tb.Text;
    da.Update(ds, "Customers");
    DataGrid1.EditItemIndex = -1;
    DataGrid1.DataBind();
    }
    }
    }



  2. #2

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    28

    Re: [RESOLVED] Having trouble using edit link to edit in datagrid....

    dangit, i had to go into Events and tell it what event to run for which. got it solved... shesh, thats a breathe of fresh air

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width