R
Ravichandran Mahalingam
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.
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.