I have a whole of things to learn about gridview and multiple tables; let me try to explain more what I want to know:
If I have a gridview in my project where records are being display from database based on the logged-in user (Admin), selected value in the dropdown list and between dates, and for each table depending on the data in each of the table records will be displayed. From what I have, if a table contains image data then an image will be displayed along with other datas but if a tables does not contain image data then no image will be displayed but image column will still be visible I don’t want image column to be visible for tables with no image data. Once a table without image data is selected from the dropdown list to display in the gridview, the image column should hide.
Another issue is, when I select table to display in gridview, and I want to delete record in that table that is displaying how can I do it? Since it is not one table that displays in the gridview.
For example, I select table1 to display and it displays, it is the same DeleteButton that will be shown even if I choose another table (Table3) from the dropdown list to display. Since this DeleteButton will appear in all table records, there is only one command event tied to that DeleteButton to delete records. SO HOW CAN I POSSIBLE TO DELETE RECORD IN GRIDVIEW BASED ON THE TABLE SELECTED FROM DROPDOWN LIST?
Also, if record can deleted from any table with one DeleteButton in gridview, will it also have to be based on Between dates or just based on table name regardless of the date the record was being created?
Here is C# to delete record from gridview and in table where the record is in. But I don’t want it to be tied to only Users Table as shown in the query string “DELETE FROM Users WHERE Uid=@Uid”
protected void OnRowDeleting(object sender, GridViewDeleteEventArgs e)
{
int Uid = Convert.ToInt32(AdminGrid.DataKeys[e.RowIndex].Values[0]);
string query = "DELETE FROM Users WHERE Uid=@Uid";
using (SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Dataregister.mdf;Integrated Security=True"))
{
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.Parameters.AddWithValue("@Uid", Uid);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
this.BindGrid();
}