I am currently developing a website. I have an a code in my external js file
function DeleteConfirm(rfqcodeLB) {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm("Are you sure you want to delete" + rfqcodeLB +" ?")) {
confirm_value.value = "Yes";
} else {
confirm_value.value = "No";
}
document.forms[0].appendChild(confirm_value);
}
What I want to do is get the id of the selected row in the gridview. What i did was transfer the selected code into string which is rfqcodeLB. And then put the attribute to the button. But it shows null.
Can someone please help me? Thanks.
<asp:ImageButton ImageUrl="../Pictures/Icons/deleteblack.png" runat="server" OnClick="Unnamed_Click" ID="deleteBT" OnClientClick="return DeleteConfirm(ContentPlaceHolder1_rfqcodeLB);"/>
将id作为函数参数传递,而不是ContentPlaceHolder1_rfqcodeLB,请使用this.id。
You need to send the RowIndex
to the JavaScript function. Not this.id
, that will only get you the ID of the ImageButton.
<asp:ImageButton OnClientClick='<%# "return DeleteConfirm(" + Container.DataItemIndex + ");" %>' ImageUrl="../Pictures/Icons/deleteblack.png" runat="server" OnClick="Unnamed_Click" ID="deleteBT"/>
Or if you want a database value
OnClientClick='<%# "return DeleteConfirm('" + Eval("yourID") + "');" %>'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.