-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: a.a.
Message 1 in Discussion

Hi, I have created a datagrid and populated it using a dataset and then use the edit 
column to change values in a datarid row. My aim is to change the dataset values 
without changing the datatable values. I find that after changing the page no. and 
then coming back to the original page the new values are lost and the old values are 
retained. The same happens with sorting. How can i retain and display the new values 
in the datagrid and dataset without updating the datatable.   The code used is as 
follows, DATAGRID CONTROL       <asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; 
POSITION: relative" runat="server" Width="270px" Height="210px" 
AutoGenerateColumns="false" AllowPaging="true" AllowSorting="true" PageSize="10" 
HeaderStyle-BackColor="#ffcc33" OnPageIndexChanged="paging" OnSortCommand="sorting" 
CssClass="normaltext" OnCancelCommand="dgcancel" OnEditCommand="dgedit" 
OnUpdateCommand="dgupdate">
    <AlternatingItemStyle BackColor="#CCFF99" 
CssClass="alternatingitemstyle"></AlternatingItemStyle>
    <HeaderStyle CssClass="tableheader"></HeaderStyle>
    <PagerStyle NextPageText="Next" PrevPageText="Prev" HorizontalAlign="Center" 
BackColor="#FFE0C0" Mode="NumericPages"></PagerStyle>
    <Columns>
     <asp:EditCommandColumn EditText="edit" UpdateText="submit" 
CancelText="cancel"></asp:EditCommandColumn>
     <asp:BoundColumn SortExpression="COMPANY_ID_PK" DataField="COMPANY_ID_PK" 
HeaderText="Company"></asp:BoundColumn>
     <asp:BoundColumn SortExpression="TRAN_ID" DataField="TRAN_ID" 
HeaderText="T.No."></asp:BoundColumn>
     <asp:BoundColumn SortExpression="TRAN_DATE" DataField="TRAN_DATE" 
HeaderText="T.Date" ItemStyle-Width="150"></asp:BoundColumn>
     <asp:BoundColumn SortExpression="CLIENT_ACCOUNT_CD" DataField="CLIENT_ACCOUNT_CD" 
HeaderText="C.A/c"></asp:BoundColumn>
     <asp:BoundColumn SortExpression="DEBTOR_ACCOUNT_CD" DataField="DEBTOR_ACCOUNT_CD" 
HeaderText="D.A/c"></asp:BoundColumn>
     <asp:BoundColumn SortExpression="CLIENT_CURRENCY" DataField="CLIENT_CURRENCY" 
HeaderText="C.Currency"></asp:BoundColumn>
     <asp:BoundColumn SortExpression="DEBTOR_CURRENCY" DataField="DEBTOR_CURRENCY" 
HeaderText="D.Currency"></asp:BoundColumn>
     <asp:BoundColumn SortExpression="CREATED_BY" DataField="CREATED_BY" 
HeaderText="Created by"></asp:BoundColumn>
    </Columns>
   </asp:DataGrid><br>
   <asp:TextBox id="TextBox1" style="Z-INDEX: 101; POSITION: relative" 
runat="server"></asp:TextBox>
   CODEBEHIND (.ASPX.CS) using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using pro;
using System.Configuration; namespace pro
{
 /// <summary>
 /// Summary description for WebForm1.
 /// </summary>
 public class WebForm1 : System.Web.UI.Page
 {   protected System.Web.UI.WebControls.Label lblmsg;
  protected System.Web.UI.WebControls.DataGrid DataGrid1;
  protected DataSet ds;
  protected OleDbDataAdapter da;
  protected DataView dv;
  protected DataTable dt;
  private string sortview;
  private int pageno;
  protected System.Web.UI.WebControls.Label hdnpageindex;
  protected System.Web.UI.WebControls.Label hdnsortview;
  protected System.Web.UI.WebControls.TextBox TextBox1;   dbcon conn = new dbcon();
  
 
  public void Page_Load(object sender, System.EventArgs e)
  {
   if (Page.IsPostBack)
   {
   }
   else //if the page is fresh or not been posted.
   {
    sortview = "DEBTOR_ACCOUNT_CD";
    dbconnect();
    pageandsort();
   }
  }   public void dbconnect()
  {
   string sql = "select COMPANY_ID_PK, TRAN_ID, TRAN_DATE," +
    "CLIENT_ACCOUNT_CD, DEBTOR_ACCOUNT_CD, CLIENT_CURRENCY," +
    "DEBTOR_CURRENCY, CREATED_BY from FCT_CHARGES";
   da = new OleDbDataAdapter(sql,conn.dbconn());    ds = new DataSet();
   da.Fill(ds,"FCT_CHARGES");
   dt = ds.Tables["FCT_CHARGES"];
  }   protected void pageandsort()
  {
   try
   {     if (pageno.ToString()=="" || pageno.ToString()==null || 
pageno.ToString()=="0") 
    {
     if(hdnpageindex.Text.Length>0)pageno = 
Convert.ToInt16(hdnpageindex.Text.ToString());
    }
    if (sortview=="" || sortview==null)sortview = hdnsortview.Text;
    
    dv = new DataView(dt,"",sortview,DataViewRowState.CurrentRows);
    DataGrid1.CurrentPageIndex = pageno;
    databind();
   }
   catch (Exception E)
   {
    Response.Write (E.ToString());
   }
  }   protected void databind()
  {
   DataGrid1.DataSource = dv;
   DataGrid1.DataBind();
  }   protected void paging(Object sender, DataGridPageChangedEventArgs e)
  {
   pageno = e.NewPageIndex;
   if (pageno.ToString()!="" || pageno.ToString()!=null) hdnpageindex.Text = 
pageno.ToString();
   pageandsort();
  }
  
  public void sorting(Object sender, DataGridSortCommandEventArgs e)
  {
   sortview = e.SortExpression.ToString();
   if (sortview!="" || sortview!=null) hdnsortview.Text = sortview;
   pageandsort();
  }   #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.Load += new System.EventHandler(this.Page_Load);
   dbconnect();
  }
  #endregion   protected void dgcancel(Object sender, DataGridCommandEventArgs e)
  {
   lblmsg.Text = "";
   DataGrid1.EditItemIndex = -1;
   //Response.Write (DataGrid1.EditItemIndex.ToString());
   pageandsort();
  }   protected void dgedit(Object sender, DataGridCommandEventArgs e)
  {
   lblmsg.Text = "";
   DataGrid1.EditItemIndex = e.Item.ItemIndex;
   //Response.Write (DataGrid1.EditItemIndex.ToString());
   pageandsort();
  }   protected void dgupdate(Object sender, DataGridCommandEventArgs e)
  {    Response.Write("<br>ds.HasChanges1 = "+ds.HasChanges()+", ds.HasErrors1 = 
"+ds.HasErrors);
   string[] cols = 
{"COMPANY_ID_PK","TRAN_ID","TRAN_DATE","CLIENT_ACCOUNT_CD","DEBTOR_ACCOUNT_CD","CLIENT_CURRENCY","DEBTOR_CURRENCY","CREATED_BY"};
   int NumCols = e.Item.Cells.Count;
   for (int i = 0; i<NumCols-1; i++)
   { 
    TextBox1 = (TextBox)e.Item.Cells[i+1].Controls[0]; 
ds.Tables[FCT_CHARGES].Rows["+DataGrid1.EditItemIndex+"]["+cols[i]+"]="+TextBox1.Text+"");
    ds.Tables["FCT_CHARGES"].Rows[DataGrid1.EditItemIndex][cols[i]]=TextBox1.Text;    
}    Response.Write("<br>ds.HasChanges2 = "+ds.HasChanges()+", ds.HasErrors2 = 
"+ds.HasErrors);
   Response.Write("<br>ds.Relations = "+ds.Relations.Count);    ds.AcceptChanges();
   da.Fill(ds,"FCT_CHARGES");
   Response.Write("<br>ds.HasChanges3 = "+ds.HasChanges()+", ds.HasErrors3 = 
"+ds.HasErrors);
  }  }
}

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to