hello
I have problem when select to stats and use oncancel/ondelete its hide all users data.
When i select city and i use oncancel/ondelete there is no problem.
I would like add condition if for this code behind.
if i select country and press oncancel
BindGridView2
if i select city user
BindGridView
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table class="auto-style177" dir="rtl">
<tr class="auto-style178">
<td style="border: medium solid #000000">
</strong><strong>
<asp:DropDownList ID="ddlCountries" runat="server" AutoPostBack="true" CssClass="auto-style179" OnSelectedIndexChanged="Country_Changed">
</asp:DropDownList>
</strong></td>
<td style="border: medium solid #000000"><strong>
<asp:DropDownList ID="ddlStates" runat="server" AutoPostBack="true" CssClass="auto-style179" OnSelectedIndexChanged="State_Changed">
</asp:DropDownList>
</strong></td>
<td style="border: medium solid #000000"><strong>
<asp:DropDownList ID="ddlCities" runat="server" AutoPostBack="True" CssClass="auto-style179" OnSelectedIndexChanged="Cities_Changed">
</asp:DropDownList>
</strong></td>
</tr>
</table>
<hr />
<asp:TemplateField HeaderText="حالة الطلب">
<ItemTemplate>
<asp:Button ID="btnNewRequestsp1" runat="server" CommandArgument="<%# Container.DataItemIndex %>" CssClass="button3" Font-Bold="True" Height="35px" Width="100px" OnClick="OnDeletesp" Text="معتمد" Visible='<%# Eval("CountryId2").ToString() == "Cancelled" ? true : false %>' />
<asp:Button ID="btnNewRequestsp2" runat="server" CommandArgument="<%# Container.DataItemIndex %>" CssClass="button3" Font-Bold="True" Height="35px" Width="100px" OnClick="OnCancelsp" Text="غير معتمد" Visible='<%# Eval("CountryId2").ToString() == "return" ? true : false %>' />
</ItemTemplate>
<FooterStyle Width="100px" />
</asp:TemplateField>
private void BindGridView()
{
string constr = ConfigurationManager.ConnectionStrings["cmConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
string query = "SELECT * FROM Table_infoname WHERE Cities = @Cities ";
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.Parameters.AddWithValue("@Cities", ddlCities.SelectedItem.Text);
GridView1.Columns[6].Visible = false;
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
}
}
private void BindGridView2()
{
string constr = ConfigurationManager.ConnectionStrings["cmConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
string query = "SELECT * FROM Table_infoname WHERE States = @States ";
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.Parameters.AddWithValue("@States", ddlStates.SelectedItem.Text);
GridView1.Columns[6].Visible = true;
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
}
}
protected void OnCancelsp(object sender, EventArgs e)
{
GridViewRow row = (sender as Button).NamingContainer as GridViewRow;
string conString = ConfigurationManager.ConnectionStrings["cmConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand("UPDATE Table_infoname SET CountryId2 = @CountryId2, dateadd2 = @dateadd2 WHERE id=@id", con))
{
string id = GridView1.DataKeys[row.RowIndex].Values[0].ToString();
cmd.Parameters.AddWithValue("@CountryId2", "Cancelled");
cmd.Parameters.AddWithValue("@dateadd2", new DateTime(2023, 01, 01));
cmd.Parameters.AddWithValue("@id", id);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
this.BindGridView2();
}
protected void OnDeletesp(object sender, EventArgs e)
{
GridViewRow row = (sender as Button).NamingContainer as GridViewRow;
string conString = ConfigurationManager.ConnectionStrings["cmConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand("UPDATE Table_infoname SET CountryId2 = @CountryId2, dateadd2 = @dateadd2 WHERE id=@id", con))
{
string id = GridView1.DataKeys[row.RowIndex].Values[0].ToString();
cmd.Parameters.AddWithValue("@CountryId2", "return");
cmd.Parameters.AddWithValue("@dateadd2", SqlDbType.DateTime).Value = DateTime.Now;
cmd.Parameters.AddWithValue("@id", id);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
this.BindGridView();
}