我正在尝试选择一个 GridView 行,并将其 id 保存到一个变量中,然后在超链接中使用这个 id 来删除该行。
问题是 id=9 一直,即使没有点击任何行。
这是代码:
string id;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add(
"onmouseover",
"this.style.cursor='Pointer';this.style.backgroundColor='Yellow'");
e.Row.RowIndex.ToString()));
id = DataBinder.Eval(e.Row.DataItem, "ProductionOrderId").ToString();
}
}
这是超链接代码
<a href='<%=ResolveUrl("~/Producter/Delete?id=" + id) %>' ID="HyperLink1">Delete</a>
这是删除功能应该是
namespace MvcApplication3.Controllers
{
public class TEstController : Controller
{
//
// GET: /TEst/
public ActionResult Index()
{
var db = new DataClasses1DataContext();
var list = from d in db.Orders
select d;
ViewData["list"] = list;
return View();
}
public ActionResult Delete(Object id)
{
// TODO
// Delete thr user which its id = obj.id ;
return View();
}
}
}