locked
How to remove a row from a dynamic table in c# RRS feed

  • Question

  • User1152304826 posted
    protected void chkRow_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox chkrow = (CheckBox)sender;
            
            
                GridViewRow row = (GridViewRow)chkrow.NamingContainer;
                string _facil = string.Empty;
                string _exportDate = DateTime.Now.ToString("MM/dd/yyyy");
                if (_exportDate.Contains('-'))
                    _exportDate = _exportDate.Replace('-', '/');
    
                if (ddlfacility.SelectedIndex > 0)
                    _facil = ddlfacility.SelectedValue;
    
                if (ViewState["selectedRowsFromGrid"] == null)
                {
                    System.Data.DataTable dtDynamic = new System.Data.DataTable();
    
                    dtDynamic.Columns.Add("MRN", typeof(string));
                    dtDynamic.Columns.Add("Patient Name", typeof(string));
                    dtDynamic.Columns.Add("Surgeon", typeof(string));
                    dtDynamic.Columns.Add("Procedure", typeof(string));
                    dtDynamic.Columns.Add("Export Date", typeof(string));
                    dtDynamic.Columns.Add("DOS", typeof(string));
                    dtDynamic.Columns.Add("Sex", typeof(string));
                    dtDynamic.Columns.Add("Home Phone", typeof(string));
                    dtDynamic.Columns.Add("Facility", typeof(string));
                    dtDynamic.Columns.Add("Return", typeof(string));
                    
                        dtDynamic.Rows.Add(row.Cells[1].Text, row.Cells[2].Text, row.Cells[5].Text, row.Cells[3].Text, _exportDate, row.Cells[7].Text, "", "", _facil, "");
                        dtDynamic.Rows.Add("Notes:____ ");
                        dtDynamic.Rows.Add("");
                        ViewState["selectedRowsFromGrid"] = dtDynamic;
                    
    
                }
                else
                {
                    System.Data.DataTable dtDynamic = (System.Data.DataTable)ViewState["selectedRowsFromGrid"];
                    dtDynamic.Rows.Add(row.Cells[1].Text, row.Cells[2].Text, row.Cells[5].Text, row.Cells[3].Text, _exportDate, row.Cells[7].Text, "", "", _facil, "");
                    dtDynamic.Rows.Add("Notes:____ ");
                    dtDynamic.Rows.Add("");
                    ViewState["selectedRowsFromGrid"] = dtDynamic;
                }
            
        }
    

    I have this code which inserts a record in a dynamic table when a row is checked in a grid view.  How can I remove the row from the dynamic table when the check box is unchecked?

    Monday, December 9, 2013 4:13 PM

Answers