using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Configuration;
using
System.Data.SqlClient;
using
System.Data;
namespace
WebApplication4
{
public
partial
class
_Default : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(
!
Page.IsPostBack)
{
DataLoad();
}
}
public
void
DataLoad()
{
this
.GridView1.DataSource
=
Table();
this
.GridView1.DataBind();
}
public
static
DataSet Table()
{
using
(SqlConnection conn
=
new
SqlConnection (ConfigurationManager.ConnectionStrings[
"
learning
"
].ConnectionString))
{
conn.Open();
SqlCommand cmd
=
conn.CreateCommand();
cmd.CommandText
=
"
select top 10 * from users
"
;
SqlDataAdapter adapter
=
new
SqlDataAdapter(cmd);
DataSet ds
=
new
DataSet();
adapter.Fill(ds);
return
ds;
}
}
protected
void
Button1_Click1(
object
sender, EventArgs e)
{
Response.Write(
"
request取id
"
);
//
获取checkbox绑定的id;以name名称获取请求
string
s
=
Request[
"
Chec1
"
].ToString();
Response.Write(Request[
"
Chec1
"
].ToString());
///////////////////////////////////////////////////////////////
/
Response.Write(
"
label绑定遍历取值取id
"
);
//
获取label绑定的值
string
selectId
=
""
;
for
(
int
i
=
0
; i
<
this
.GridView1.Rows.Count; i
++
)
{
//
找到gridview上的CheckBox控件
CheckBox ch
=
this
.GridView1.Rows[i].Cells[
1
].FindControl(
"
CheckBox1
"
)
as
CheckBox;
if
(ch
!=
null
)
{
if
(ch.Checked)
{
//
找到第i行第一个格子上的label控件,即是刚才绑定的label
Label lb
=
this
.GridView1.Rows[i].Cells[
0
].FindControl(
"
Label2
"
)
as
Label;
//
将label的值取出来用“,”号分开
selectId
=
selectId
+
"
,
"
+
lb.Text;
}
}
}
if
(selectId.Length
>
1
)
{
selectId
=
selectId.Substring(
1
);
}
Response.Write(selectId);
}
}
}