Do Web development or novice me, in order to get the value in the GridView, it was to save the data in the GridView to the server via the server-side control, then bind to a server-side hidden field, then read the values in the hidden fields through JS, and now it feels stupid. , although it is easy to get the data is simply to traverse the GridView, but consider the performance, I would like to use JS to read. Now I can get the data I want, in order to facilitate the same novice as me, now easy to write down, hope to be able to find a better solution. If you have a better idea please contact qq:643166601, I will record the update in time.
1. Prepare the database, my database name is called LIONDB, there is a table below called user, as follows:
The user table is defined as follows:
The data in the user table is as follows:
2. Place two controls on the page
A) GridView, binding data source, adding checkbox columns, other columns automatically bound
b) Input (Button), add an event (for the next specific line or a few lines of data to prepare)
After that, the page effect is as follows:
4.js Key Code
<script language= "javascript" type= "Text/javascript" >
//<![ cdata[
function Btnchecked_onclick () {
var TB = document.getElementById ("<%=gridview1.clientid%>");
var sline = "";
if (TB) {
var rows = tb.rows;
for (var i = 1; i < rows.length i++) {
var cbx = rows[i].cells[0].childnodes[0].nextelementsibling;
if (Cbx.type = = ' checkbox ' && cbx.checked = = True) {
var suserid = rows[i].cells[1].innerhtml;
var susername = rows[i].cells[2].innerhtml;
Sline + + "UserId:" + sUserID + "UserName:" + sUserName + "";
}
}
alert (sline);
}
}
]]>
</script>
5. Operation effect
6. Get the results you want
SOURCE Package:
Click to open the link