DG-Edit-Loosing data; bound columns - pushbuttons; dataReader

Discussion in 'ASP .Net Datagrid Control' started by Ravichandran Mahalingam, Jan 8, 2004.

  1. Dear Readers,

    I am using C# (vb examples will work for me too - i am vb progrmr). I
    created a dg (datagrid) with bound columns (hesistant to make them
    template). I used myConn, strSQL, and drMyReader to get the data
    succesfully in the grid. the key fields to the db are 4 fields.

    I downloaded a datagrid program from gotdotnet.com and they are using
    the same way as I do - the only difference is that they have mentioned
    the datakeyfield parameter in the datagrid html source - since it is 1
    field, it was easy for the demo.

    The grid loads with the data fine for the 1st time.

    when I clicked the edit, (I had the OnEditCommand/OnUpdateCOmmand in
    the HTML source), the program runs the page_load more than once and
    displays an empty grid. Not to say, I am not updating the values.

    Surprising the demo is using sql statements to update the values (in
    the traditional ADO way) instead of using da (dataAdapter).update.
    the examples on the internet with da.Update is also not working.

    da.Edit is also not working.

    any input will be appreciated. I hate to paste my code. but still it
    is available.
    thanks and regards
    Ravi.
    ************************************************
    private void Page_Load(object sender, System.EventArgs e)
    {
    if (!Page.IsPostBack)
    {
    GetSessionValues();
    GetDataToGrid();
    }

    }
    private void GetDataToGrid()
    {
    cmdSqlSelect.CommandType = CommandType.Text;
    cmdSqlSelect.CommandText= "Select SuppFacilitySeqNum, FacilityName,
    FacLicenseNum, PatientBedsNum from OtherFacilitiesInfo where
    HospitalId ='" + strHospitalId + "' and YearFiled ='" +
    strYearFiled + "' and SuppFacilityType = 'EM'";

    cmdSqlSelect.Connection = sqlConn;
    sqlConn.Open();
    try
    {
    drOtherFac = cmdSqlSelect.ExecuteReader(CommandBehavior.Default);

    grdEmergency.DataSource=drOtherFac;
    grdEmergency.DataBind();
    }
    catch (Exception exc)
    {
    lblError.Text = exc.ToString();

    }
    finally
    {
    sqlConn.Close();
    }

    }
    private void GetSessionValues()
    {

    strFacName = "A new Facility Name ";
    strHospitalId = "55669";
    strYearFiled = "2001";

    lblFacilityName.Text = strFacName;
    txtHospitalId.Text = strHospitalId;
    txtYearFiled.Text = strYearFiled;
    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    InitializeComponent();
    base.OnInit(e);
    }


    private void InitializeComponent()
    {
    //MYSQL CONN DEFINED HERE WITH ALL
    THE
    this.grdEmergency.update.... all those statements.
    }
    #endregion
    public void grdEmergency_EditCommand(object source,
    DataGridCommandEventArgs e)
    {
    grdEmergency.EditItemIndex = e.Item.ItemIndex;
    GetDataToGrid();
    }

    ......
    **********************end of code.
     
    Ravichandran Mahalingam, Jan 8, 2004
    #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. Bigtoga
    Replies:
    1
    Views:
    666
    Chee Seong Ong
    Apr 28, 2004
  2. Bazza Formez
    Replies:
    9
    Views:
    498
    Bazza Formez
    Dec 9, 2004
  3. Mario Krsnic
    Replies:
    0
    Views:
    390
    Mario Krsnic
    Jun 23, 2006
  4. Alexandru Mihai via .NET 247

    it works with pushbuttons

    Alexandru Mihai via .NET 247, Jun 15, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    113
    Alexandru Mihai via .NET 247
    Jun 15, 2004
  5. Vinki

    template columns and bound columns in gridview

    Vinki, Apr 25, 2007, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    888
    Vinki
    Apr 25, 2007
Loading...

Share This Page