我找不到我的问题的任何解决方案。 这是一个MVC项目我的工作。
在GridView我怎么可以这样做: Click on row and then click on button to delete this selected or clicked row.
不需要自动选择按钮的任何解决方案。
所以
鼠标点击该行
得到它的ID号或任何价值
按钮重定向到我的功能+编号。
它是不可能的GridView的? 它会更好,如果我使用表?
这是我曾尝试:
//To get the id
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.RowIndex.ToString();
string id = DataBinder.Eval(e.Row.DataItem, "Id").ToString();
e.Row.Attributes.Add("rowid", id);
}
}
我的JavaScript的按钮
<a href='<%=ResolveUrl("~/Producter/Delete?id=" ) %>' ID="HyperLink1">Delete</a>
<script type ="text/javascript" language="javascript">
//every time a row is clicked this script will perform the following actions:
$("tr").click(function () {
var clicked = $(this);
//get the row id from the currently cliked row
var rowid = clicked.attr("rowid");
//get the value of href attribute from the link with id 'HyperLink1'
var link = $("#HyperLink1").attr("href");
//remove any previously appended values
var linkTokens = link.split("=");
linkTokens[1] = "";
link = linkTokens.join("=");
//append the current row id to the link
link = link + rowid;
//set the href attribute of your link to the new value
$("#HyperLink1").attr("href", link);
});
</script>
有ID =未定义所有的时间。