调用“删除”链接的正确方法?
使用jquery,当我单击链接“ Remove”时如何调用该函数?
在引导程序模式内
我的HTML:
<table>
<tr>
<td valign="">
<div id="imgtag">
<center><div id="uploads3"><?php echo $eq_picPa; ?></div></center>
<div id="tagbox">
</div>
</div>
</td>
<td valign="top">
<div id="taglist">
<span class="tagtitle">List of Tags</span>
<ol>
<li rel="1"><a>jelly</a> (<a class="remove">Remove</a>)</li>
</ol>
</div>
</td>
</tr>
</table>
我的JS:
$('#taglist').on('click', 'li a.remove',function(){
alert('hi');
id = $(this).parent().attr("rel");
type = "remove";
// get all tag on page load
$.ajax({
type: "POST",
url: "savetag.php",
data: {"id": id, "type": type},
success: function(data){
viewtag();
}
});
});
答案 0 :(得分:0)
这可能对您有帮助
public partial class table : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlcon"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
if (!Page.IsPostBack)
{
BindEmpGrid();
txtSearch.Enabled = false;
}
}
private void BindEmpGrid()
{
SqlDataAdapter adp = new SqlDataAdapter();
DataTable dt = new DataTable();
try
{
adp = new SqlDataAdapter("select * from Emp", con);
adp.Fill(dt);
if (dt.Rows.Count > 0)
{
grdEmp.DataSource = dt;
grdEmp.DataBind();
}
else
{
grdEmp.DataSource = null;
grdEmp.DataBind();
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true);
}
finally
{
dt.Clear();
dt.Dispose();
adp.Dispose();
con.Close();
}
}
protected void ddlSearchBy_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlSearchBy.SelectedItem.Text == "All")
{
txtSearch.Text = string.Empty;
txtSearch.Enabled = false;
}
else
{
txtSearch.Enabled = true;
txtSearch.Text = string.Empty;
txtSearch.Focus();
}
}
protected void btnSearch_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter adp = new SqlDataAdapter();
try
{
if (ddlSearchBy.SelectedItem.Text == "Employee_ID")
{
getEmpRecords(ddlSearchBy.SelectedItem.Text, txtSearch.Text.Trim());
}
else if (ddlSearchBy.SelectedItem.Text == "Employee_name")
{
getEmpRecords(ddlSearchBy.SelectedItem.Text, txtSearch.Text.Trim());
}
else if (ddlSearchBy.SelectedItem.Text == "Mobile")
{
getEmpRecords(ddlSearchBy.SelectedItem.Text, txtSearch.Text.Trim());
}
else
{
getEmpRecords(ddlSearchBy.SelectedItem.Text, txtSearch.Text.Trim());
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true);
}
finally
{
dt.Clear();
dt.Dispose();
cmd.Dispose();
con.Close();
}
}
private void getEmpRecords(string searchBy, string searchVal)
{
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter adp = new SqlDataAdapter();
try
{
cmd = new SqlCommand("all", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@SearchBy", searchBy);
cmd.Parameters.AddWithValue("@SearchVal", searchVal);
adp.SelectCommand = cmd;
adp.Fill(dt);
if (dt.Rows.Count > 0)
{
grdEmp.DataSource = dt;
grdEmp.DataBind();
}
else
{
grdEmp.DataSource = dt;
grdEmp.DataBind();
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true);
}
finally
{
dt.Clear();
dt.Dispose();
cmd.Dispose();
con.Close();
}
}
protected void grdEmp_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
grdEmp.PageIndex = e.NewPageIndex;
BindEmpGrid();
}
protected void grdEmp_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void grdEmp_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Del")
{
int EmpID = int.Parse(e.CommandArgument.ToString());
DeleteRecord(EmpID);
BindEmpGrid();
}
if (e.CommandName == "Edit")
{
string EmpID = e.CommandArgument.ToString();
Response.Redirect("update.aspx?Id="+ EmpID);
}
}
private void DeleteRecord(int EmpID)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "delete from Emp where Employee_ID = @a";
cmd.Parameters.AddWithValue("@a", EmpID);
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
}
}
选中此fiddle