| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Work with all your cloud files (Drive, Dropbox, and Slack and Gmail attachments) and documents (Google Docs, Sheets, and Notion) in one place. Try Dokkio (from the makers of PBworks) for free. Now available on the web, Mac, Windows, and as a Chrome extension!

View
 

Lecture - How To - Create Forms that Update

Page history last edited by Dr. Ron Eaglin 9 years, 6 months ago

 

Create Forms that Update

 

Prerequisites

 

Lecture - Form Objects - Buttons

Lecture - Form Objects - GridView

Adding Item Templates to Datagrid

How to Pass Variables Between Web Forms

 

 

Summary

 

This video demonstrates how to add a template column to a GridView, pulls a value from the GridView and adds it into the Session. This is then passed to a second form that uses the value to pull data from the database and also go into Update Mode.

 

Video 

 

http://online1.daytonastate.edu/player2.php?id=1bf0c59238dd24a7f09a889483a50e8f 

 

Reference Materials

 

In the Gridview -

Use of ComandName - http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.commandeventargs.commandname.aspx 

Use of CommandArgument - http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.commandeventargs.commandargument 

Use of OnRowCommand - http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.onrowcommand%28v=vs.90%29.aspx 

Creating a Template Column - http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.templatefield.itemtemplate.aspx 

 

DatabaseHelper Class (as used in this example)

    public class DatabaseHelper
    {
        #region "Static Methods"
        public static string connectionString()
        {
            return DatabaseHelper.connectionString("TraumaFlowConnectionString");
        }
        public static string connectionString(string connName)
        {
            System.Configuration.Configuration rootWeb = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/TraumaFlow");
            System.Configuration.ConnectionStringSettings connstr;
            if (rootWeb.ConnectionStrings.ConnectionStrings.Count > 0)
            {
                connstr = rootWeb.ConnectionStrings.ConnectionStrings[connName];
                return connstr.ConnectionString;
            }
            return String.Empty;
        }
        public static void fillTextBox(TextBox tb, string XMLName, int TraumaFormID)
        {
            tb.Text = getValue(XMLName, TraumaFormID);
        }
        public static string getValue(string XMLName, int TraumaFormID)
        {
            if (XMLName == "PatientReportedName") return DatabaseHelper.getPatientName(TraumaFormID);
            string sql = "SELECT Value FROM view_TextMedicalData ";
            sql += "WHERE XMLName = '" + XMLName +"'";
            sql += " AND id = " + Convert.ToString(TraumaFormID);
            return DatabaseHelper.executeSqlReturnString(sql);
        }
        public static string getPatientName(int TraumaFormID)
        {
            string sql = "SELECT name FROM TraumaForm WHERE id = '" + TraumaFormID.ToString() + "'";
            return DatabaseHelper.executeSqlReturnString(sql);
        }
        public static int getCodeID(string XMLName, int TraumaFormID)
        {
            string sql = "SELECT CodeID FROM view_CodedMedicalData ";
            sql += "WHERE XMLName = '" + XMLName + "'";
            sql += " AND id = " + Convert.ToString(TraumaFormID);
            return Convert.ToInt32(DatabaseHelper.executeSqlReturnString(sql));
        }
        public static string executeSqlReturnString(string sql)
        {
            // Should be the first element in the DataTable
            DataTable dt = DatabaseHelper.executeSqlReturnDataTable(sql);
            if (dt.Rows.Count >= 1)
                return Convert.ToString(dt.Rows[0][0]);
            else
                return String.Empty;
        }
        public static DataTable executeSqlReturnDataTable(string sql)
        {
            SqlConnection connection = new SqlConnection(DatabaseHelper.connectionString());
            SqlCommand command = new SqlCommand(sql, connection);
            SqlDataAdapter a = new SqlDataAdapter(command);
            DataTable dt = new DataTable();
            a.Fill(dt);
            return dt;
        }
        #endregion
    } 
 

Screen Captures

 

 

Additional Information

 

 

 

 

COP 4834 Lectures Page

Comments (0)

You don't have permission to comment on this page.