62,047
社区成员
发帖
与我相关
我的任务
分享
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script type="text/javascript" language="javascript">
function GetLinkInfo(Obj,PhTmp)
{
var StrTmp=document.all["PhIDHidden"].value;
if(StrTmp=="")
{
document.all["PhIDHidden"].value=PhTmp;
}
else
{
var ArrStrTmp=StrTmp.split(",");
var StrExist="0";
var qq=0;
for(qq=0;qq<=ArrStrTmp.length-1;qq++)
{
if(ArrStrTmp[qq]==PhTmp)
{
StrExist="1";
break;
}
}
if(Obj.checked==true)
{
if(StrExist!="1")
{
document.all["PhIDHidden"].value=StrTmp+","+PhTmp;
}
}
else
{
if(StrExist=="1")
{
var tmptmp="";
if(qq==0)
{
document.all["PhIDHidden"].value=StrTmp.substring(StrTmp.indexOf(",")+1);
if(qq==ArrStrTmp.length-1)
{
document.all["PhIDHidden"].value="";
}
}
else
{
if(qq==ArrStrTmp.length-1)
{
document.all["PhIDHidden"].value=StrTmp.substring(0,StrTmp.lastIndexOf(","));
}
else
{
tmptmp=","+PhTmp+",";
document.all["PhIDHidden"].value= StrTmp.replace(tmptmp,",");
}
}
}
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input id="PhIDHidden" runat="server" type="hidden" />
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id">
<Columns>
<asp:BoundField DataField="id" HeaderText="id" ReadOnly="True" SortExpression="id" />
<asp:BoundField DataField="title" HeaderText="title" SortExpression="title" />
<asp:BoundField DataField="author" HeaderText="author" SortExpression="author" />
<asp:TemplateField>
<ItemTemplate>
<input id="chkExport" type="checkbox" runat="server"/>
</ItemTemplate>
<HeaderTemplate>
<asp:LinkButton ID="DelBts" runat="server" OnClick="Del_Click">删除</asp:LinkButton>
</HeaderTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=1E975CA0565B42E;Initial Catalog=message;User ID=sa;Password=123456");
SqlDataAdapter da = new SqlDataAdapter("select * from messageTable",conn);
DataSet ds = new DataSet();
da.Fill(ds,"table1");
GridView1.DataSource = ds;
GridView1.DataBind();
}
override protected void OnInit(EventArgs e)
{
//InitializeComponent();
this.GridView1.RowCreated += new GridViewRowEventHandler(RowCreated);
base.OnInit(e);
}
public void RowCreated(object sender, GridViewRowEventArgs e)
{
DataRowView view1;
if (e.Row.RowType != DataControlRowType.DataRow)
view1 = null;
else
view1 = e.Row.DataItem as DataRowView;
if (view1 == null) return;
string PhTmp = view1["id"].ToString();
HtmlInputCheckBox ChkTmp = (HtmlInputCheckBox)e.Row.FindControl("chkExport");
if (ChkTmp != null)
{
ChkTmp.Attributes.Add("onclick", "GetLinkInfo(this,'" + PhTmp + "')");
}
}
protected void Del_Click(object sender, EventArgs e)
{
if (PhIDHidden.Value != "")
{
Response.Redirect("somePage.aspx?YourId="+PhIDHidden.Value);
}
}
<asp:TemplateField HeaderText="Check">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
<HeaderStyle Width="1%" Wrap="false" />
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
protected void BtnResend_Click(object sender, EventArgs e)
{
string YourID = "";
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox CheckBox1 = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1");
if (CheckBox1.Checked)
{
YourID += GridView1.Rows[i].Cells[1].Text.Trim();
YourID += ",";
}
}
string YourIDString = YourID.TrimEnd(',');
Response.Redirect("YourPageB.aspx?YourID =" + YourID);
//也可以用session傳值