Beispiel #1
0
        protected void fetchButton_Click(object sender, EventArgs e)
        {
            if (this.Droplist_Tables.SelectedIndex == 0)
            {
                return;
            }
            else
            {
                string comboboxValue = this.Droplist_Tables.SelectedItem.Text;

                //var x = t.GetField("comboboxValue");

                using (var db = new MyConnection())
                {
                    var t = typeof(MyConnection);
                    PropertyInfo prop = t.GetProperty(this.Droplist_Tables.SelectedItem.Text);
                    var query = prop.GetValue(db, null);
                    var myType = query.GetType();
                    var connection = db.Database.Connection;

                    if (connection.State == ConnectionState.Closed)
                        connection.Open();

                    var command = connection.CreateCommand();
                    command.CommandText = query.ToString();
                    command.CommandType = CommandType.Text;

                    this.tableGrid.DataSource = command.ExecuteReader();
                    this.tableGrid.DataBind();

                    connection.Close();
                }

                //GridButtonColumn newColumn = new GridButtonColumn();
                //newColumn.HeaderText = "Options";
                //newColumn.Text = "Delete";

                //this.tableGrid.Columns.Add(newColumn);
            }
        }
Beispiel #2
0
        protected void tableGrid_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                GridDataItem item = (GridDataItem)e.Item;
                string Id = item["Id"].Text;
                //Response.Write("<script>alert('ID Selected was " + Id + " from table " + this.Droplist_Tables.SelectedItem.Text + "')</script>");

                using (var db = new MyConnection())
                {
                    try
                    {
                        db.Database.ExecuteSqlCommand("DELETE FROM " + this.Droplist_Tables.SelectedItem.Text + " WHERE ID = " + Id);
                        Response.Write("<script>alert('Successfully removed')</script>");
                    }
                    catch (Exception err)
                    {
                        Response.Write("<script>alert('Error: " + err.Message + "')</script>");
                        return;
                    }
                }
            }

            if (e.CommandName == "Details")
            {
                GridDataItem item = (GridDataItem)e.Item;
                int Id = Int32.Parse(item["Id"].Text);
                Response.Write("<script>alert('ID Selected was " + Id + " from table " + this.Droplist_Tables.SelectedItem.Text + "')</script>");
            }
        }