hello,
i have problem when add new button from gridview request delete or cancel request
if user want request delete order, it show then when red color, its work very well
so if i wantt add new button like retun or cancel request both button not working did i miss something ?
my code
<asp:TemplateField HeaderText="Request">
<ItemTemplate>
<asp:Button ID="btnNewRequest2" runat="server" Text="Request Delete" OnClick="Oncancel2" CommandArgument="<%# Container.DataItemIndex %>" BackColor="#FFFFCC" Visible='<%# Eval("CountryId").ToString() == "Cancelled" ? true : false %>'></asp:Button>
<asp:Button ID="btnNewRequest2p" runat="server" Text="Cancel Request" OnClick="Oncancel2p" CommandArgument="<%# Container.DataItemIndex %>" BackColor="#99CCFF" Visible='<%# Eval("CountryId").ToString() == "return" ? true : false %>'></asp:Button>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="70px" />
</asp:TemplateField>
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
//rasmi
if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowIndex != GridView2.EditIndex)
{
if (GridView2.DataKeys[e.Row.RowIndex].Values[0].ToString() == "Cancelled")
{
e.Row.BackColor = Color.White;
e.Row.ForeColor = Color.Black;
}
else if (GridView2.DataKeys[e.Row.RowIndex].Values[0].ToString() == "return")
{ e.Row.BackColor = Color.Red;
e.Row.ForeColor = Color.White;
}
string namerm = (e.Row.FindControl("txtUsernamelb0") as Label).Text;
string daterm = Convert.ToDateTime((e.Row.FindControl("lblBoxDateadd3") as Label).Text).ToString("dd/MM/yyyy");
foreach (LinkButton button in e.Row.Cells[9].Controls.OfType<LinkButton>())
{
if (button.CommandName == "Delete")
{
button.Attributes["onclick"] = "if(!confirm('Do you want to delet\\nأسم الموظف\\n"
+ namerm + "\\nتاريخ المهمة الرسمية\\n" + daterm + "')){ return false; };";
}
}
}
}
protected void Oncancel2(object sender, EventArgs e)
{
GridViewRow row = (sender as Button).NamingContainer as GridViewRow;
string conString = ConfigurationManager.ConnectionStrings["kankonConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand("UPDATE Table_Rsmi SET CountryId= @CountryId WHERE id=@id", con))
{
string id = GridView2.DataKeys[row.RowIndex].Values[0].ToString();
cmd.Parameters.AddWithValue("@CountryId", "Cancelled");
cmd.Parameters.AddWithValue("@id", id);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
BindGrid2Rasmi();
}
protected void Oncancel2p(object sender, EventArgs e)
{
GridViewRow row = (sender as Button).NamingContainer as GridViewRow;
string conString = ConfigurationManager.ConnectionStrings["kankonConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand("UPDATE Table_Rsmi SET CountryId= @CountryId WHERE id=@id", con))
{
string id = GridView2.DataKeys[row.RowIndex].Values[0].ToString();
cmd.Parameters.AddWithValue("@CountryId", "return");
cmd.Parameters.AddWithValue("@id", id);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
BindGrid2Rasmi();
}
private void BindGrid2Rasmi()
{
try
{
string constr = ConfigurationManager.ConnectionStrings["kankonConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand())
{
string sql = "SELECT * FROM Table_Rsmi";
if (!string.IsNullOrEmpty(civilid.Text.Trim()))
{
sql += " WHERE civilrm LIKE @civilrm + '%' ";
sql += " AND (CountryId = @Con1 OR CountryId = @Con2)";
sql += " AND MONTH(daterm) = MONTH(dateadd(dd, -1, GetDate())) ";
sql += "AND YEAR(daterm) = YEAR(dateadd(dd, -1, GetDate()))";
cmd.Parameters.AddWithValue("@civilrm", civilid.Text.Trim());
cmd.Parameters.AddWithValue("@Con1", "Cancelled");
cmd.Parameters.AddWithValue("@Con2", "return");
}
cmd.CommandText = sql;
cmd.Connection = con;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
sda.Fill(dt);
GridView2.DataSource = dt;
GridView2.DataBind();
}
}
}
}
catch (Exception)
{
}
}