Click here to Skip to main content
15,894,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
protected void updatecareplan()
        {
           TextBox thisTextBox = (TextBox)NamingContainer;
            GridViewRow thisGridViewRow = (GridViewRow)thisTextBox.NamingContainer;
            int row = thisGridViewRow.RowIndex;

            string ParameterId = Convert.ToString(grdcareplan.DataKeys[row].Values[0]);
            string strid = Convert.ToString(grdcareplan.DataKeys[row].Values[1]);

            TextBox txttargetvalue = (TextBox)grdcareplan.Rows[row].FindControl("txttargetvalue");

            //TextBox txtlastdate = (TextBox)grdcareplan.Rows[e.RowIndex].FindControl("txtlastdate");

            //TextBox txtresult = (TextBox)grdcareplan.Rows[e.RowIndex].FindControl("txtresult");
            TextBox txttestdate = (TextBox)grdcareplan.Rows[row].FindControl("txttestdate");
            TextBox txttestresult = (TextBox)grdcareplan.Rows[row].FindControl("txttestresult");

            DropDownList ddlMeasurementFrequency = (DropDownList)grdcareplan.Rows[row].FindControl("ddlMeasurementFrequency");
            //   DropDownList ddlselectdisease = (DropDownList)grdcareplan.Rows[e.RowIndex].FindControl("ddlselectdisease");
            TextBox txtnextduedate = (TextBox)grdcareplan.Rows[row].FindControl("txtnextduedate");

            TextBox txtremarks = (TextBox)grdcareplan.Rows[row].FindControl("txtremarks");
            DateTime testdt = DateTime.ParseExact(txttestdate.Text, "yy/dd/MM", null);
            //DateTime lastdate = DateTime.ParseExact(txtlastdate.Text, "yy/dd/MM", null);
            DateTime nextdate = DateTime.ParseExact(txtnextduedate.Text, "yy/dd/MM", null);
            // DateTime lastdate = Convert.ToDateTime(txtlastdate.Text);

            MySqlConnection strConnection = null;

            MySqlCommand strCommand = null;
            try
            {
                strConnection = new MySqlConnection();
                strConnection.ConnectionString = StrConn;
                strConnection.Open();
                strCommand = new MySqlCommand();
                strCommand.Connection = strConnection;


                strCommand.CommandType = CommandType.StoredProcedure;
                strCommand.CommandText = "UpdateCarePlan1";
                strCommand.Parameters.AddWithValue("_Target_value", txttargetvalue.Text.ToString());
                strCommand.Parameters.AddWithValue("_Current_Test_Date", testdt);
                strCommand.Parameters.AddWithValue("_Test_Result", txttestresult.Text.ToString());
                //strCommand.Parameters.AddWithValue("_Last_date", lastdate);
                //strCommand.Parameters.AddWithValue("_Result", txtresult.Text.ToString());
                strCommand.Parameters.AddWithValue("_Measurement_Frequency", ddlMeasurementFrequency.SelectedItem.Text.ToString());
                //strCommand.Parameters.AddWithValue("_disease_Id", ddlselectdisease.SelectedValue);
                strCommand.Parameters.AddWithValue("_Next_Due_Date", nextdate);
                //strCommand.Parameters.AddWithValue("_Remarks", txtremarks.Text.ToString());
                //strCommand.Parameters.AddWithValue("_Tenant_Id", Convert.ToInt32(Session["Tenantid"]));
                //strCommand.Parameters.AddWithValue("_Branch_Id", Convert.ToInt32(Session["Branchid"]));
                strCommand.Parameters.AddWithValue("_ParameterId", ParameterId);
                strCommand.Parameters.AddWithValue("_Patient_Id", Convert.ToInt32(Session["DiagnosisClickId"]));
                strCommand.Parameters.AddWithValue("_Modified_Date", DateTime.Now);
                strCommand.Parameters.AddWithValue("_date", DateTime.Now);
                strCommand.Parameters.AddWithValue("_Modified_By", Convert.ToInt32(Session["Doc_Id4rmLogin"]));
                strCommand.Parameters.AddWithValue("_Tenant_Id", Convert.ToInt32(Session["Tenantid"]));
                strCommand.Parameters.AddWithValue("_Branch_Id", Convert.ToInt32(Session["Branchid"]));
                //strCommand.Parameters.AddWithValue("_Id", strid);
                //strCommand.Parameters.AddWithValue("_SubTypeCode", "BIOMADE");
                //strCommand.Parameters.AddWithValue("_Active",0);
                //strCommand.Parameters.AddWithValue("_SubTypeCode", Convert.ToString(ViewState["BIOMADE"]));
                strCommand.ExecuteNonQuery();

                grdcareplan.EditIndex = -1;

                BindCarePlan();
                ModalPopupExtender1.Show();
                Biomade.Visible = true;
            }
            catch (Exception ex)
            {

                obj.InfoEntry(DateTime.Now + "     " + " BindCarePlan" + "     " + "HomeHealthCare.aspx" + "     " + ex.Message, "");
                obj.InfoEntry(DateTime.Now + "     " + ex.StackTrace, "");
                Session["strerrormsg"] = DateTime.Now + "     " + " BindCarePlan" + "     " + "HomeHealthCare.aspx" + "     " + ex.Message;
                Session["strerrortrace"] = DateTime.Now + "     " + ex.StackTrace;
                Response.Redirect("ErrorPage.aspx");
            }
            finally
            {
                strCommand.Dispose();
                strConnection.Close();
            }
        }

C#
protected void txtnextduedate_TextChanged(object sender, EventArgs e)
       {
           updatecareplan();
       }


giving error at this line
GridViewRow thisGridViewRow = (GridViewRow)thisTextBox.NamingContainer;

that object refrance not set an instance of an object
Posted
Updated 11-Mar-13 20:43pm
v2

1 solution

pass textbox object as parameter to method like :
protected void txtnextduedate_TextChanged(object sender, EventArgs e)
{
    updatecareplan(sender);
}

and update method defination like:
private static void updatecareplan(object sender)
{
    TextBox txt = (TextBox)sender;
    GridViewRow row = (GridViewRow)txt.NamingContainer;
    int index = row.RowIndex;
    // do your code here
}


this may help you
 
Share this answer
 
Comments
ujali 12-Mar-13 3:00am    
DateTime testdt = DateTime.ParseExact(txttestdate.Text, "yy/dd/MM", null);
now am getting problem on this line...
string was not recognized as valid datetime
vishal.shimpi 12-Mar-13 3:05am    
try using....
DateTime testdt = Convert.ToDateTime(txttestdate.Text);
ujali 12-Mar-13 3:09am    
still it is giving the same error
vishal.shimpi 12-Mar-13 3:13am    
whats the value is in your text box : txttestdate.Text
ujali 12-Mar-13 3:17am    
now there is no value in that textbox...
this is the field in grid..

<asp:TemplateField HeaderText="Current Date">
<itemtemplate>
<%--<asp:Label ID="Label9" runat="server" Text='<%# Bind("Current_Test_Date") %>'>--%>
<asp:TextBox ID="txttestdate" ClientIDMode="Static" runat="server" Text='<%# Bind("Current_Test_Date") %>'
CssClass="textboxInGrid" AutoPostBack="true" Width="50"
ontextchanged="txttestdate_TextChanged">
<asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txttestdate"
Format="yy/dd/MM">



This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900