62,041
社区成员
发帖
与我相关
我的任务
分享
<asp:TemplateField>
<HeaderTemplate>标题</HeaderTemplate>
<ItemTemplate> <%#Eval("scb04")%> </ItemTemplate>
<ItemStyle Width="260px" Wrap="false" HorizontalAlign="Center" CssClass="ListCellrow" />
<HeaderStyle CssClass="ListCellTitle" Wrap="false" />
</asp:TemplateField>
string sce = ""; 用来存储gridview每行的ID
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)//循环整个gridview每页的行数
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("check_xz1"); //每行前都有一个checbox.
if (cbox.Checked == true)//判断行前的checkbox是否被选中
{
message chage = new message();
sce = this.GridView1.DataKeys[i].Value.ToString(); //获取存储gridview每行的ID
SqlDataReader dr = chage.bandrecjl(sce);//从数据库中获取该文件是否被阅读
string sce06 = ""; //定义变量,存储接收的从数据库中获得文件是否被阅读的值
string sce04 = "";//定义变量,存储当前系统时间
sce04 = DateTime.Now.ToString();
if (dr.Read())
{
sce06 = dr["sce06"].ToString();
}
if (sce06 == "N")//sce06为N时,为首次阅读,调用chagerec更改sce06为Y且更改首次阅读时间
{
message chagerec = new message();
chagerec.changrec(sce, sce04);
}
if (sce06 == "Y")//sce06为Y时,为再次阅读,调用ydjl更改阅读次数和最后阅读时间.
{
message gjl = new message();
gjl.ydjl(sce, sce04);
}
Response.Redirect("readrecmsg.aspx?sce01=" + sce + ""); //将文件id传递readrecmsg.aspx页面,然后再在该页面查看通过该ID查看具体的文件内容
}
else
{
Response.Write("<script>alert('请选择要查看的通知!!')</script>");
Response.Write("<script>history.go(-1)</script>");
}
}
<asp:GridView ID="GridView1" runat="server" OnRowCommand="GridView1_RowCommand"
<asp:TemplateField HeaderText="标题">
<ItemTemplate>
<asp:LinkButton ID="lbtnRecordid" CommandName="lbtn" runat="server" ForeColor="Blue" Text='<%# DataBinder.Eval(Container.DataItem,"scb04") %>' CommandArgument='<%# Eval("sce01") %>'></asp:LinkButton>
<ItemStyle Width="260px" Wrap="False" HorizontalAlign="Center" CssClass="ListCellrow" />
<HeaderStyle CssClass="ListCellTitle" Wrap="False" />
</ItemTemplate>
</asp:GridView>
前台代码只贴出有用的..其他的样式之类的废柴代码就不贴了."GridView1_RowCommand"这个很重要..相应后台程序的.我刚开始就是没加这个..老是相应不了..!~ CommandArgument='<%# Eval("sce01") % 这个是获取你要处理的这一行的唯一标识..我是从数据库里拿出来的..所以就直接用Eval了
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)//前台定义的那个GridView1_RowCommand
{
string sce = "";//定义个变量,用来接收你选择行的唯一标识
if (e.CommandName == "lbtn")//判断你选择的是哪行
{
sce = e.CommandArgument.ToString();//定义的变量接收e.CommandArgument传递的值
//底下的都是在用接收过来的变量进行操作
message chage = new message();
SqlDataReader dr = chage.bandrecjl(sce);
string sce06 = ""; //定义变量,存储接收的sce06值.
string sce04 = "";//定义变量,存储当前系统时间
sce04 = DateTime.Now.ToString();
if (dr.Read())
{
sce06 = dr["sce06"].ToString();
}
if (sce06 == "N")//sce06为N时,为首次阅读,调用chagerec更改sce06为Y且更改首次阅读时间
{
message chagerec = new message();
chagerec.changrec(sce, sce04);
}
if (sce06 == "Y")//sce06为Y时,为再次阅读,调用ydjl更改阅读次数和最后阅读时间.
{
message gjl = new message();
gjl.ydjl(sce, sce04);
}
Response.Redirect("readrecmsg.aspx?sce01=" + sce + "");
}
}
string sce = ""; 用来存储gridview每行的ID
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)//循环整个gridview每页的行数
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("check_xz1"); //每行前都有一个checbox.
if (cbox.Checked == true)//判断行前的checkbox是否被选中
{
message chage = new message();
sce = this.GridView1.DataKeys[i].Value.ToString(); //获取存储gridview每行的ID
SqlDataReader dr = chage.bandrecjl(sce);//从数据库中获取该文件是否被阅读
string sce06 = ""; //定义变量,存储接收的从数据库中获得文件是否被阅读的值
string sce04 = "";//定义变量,存储当前系统时间
sce04 = DateTime.Now.ToString();
if (dr.Read())
{
sce06 = dr["sce06"].ToString();
}
if (sce06 == "N")//sce06为N时,为首次阅读,调用chagerec更改sce06为Y且更改首次阅读时间
{
message chagerec = new message();
chagerec.changrec(sce, sce04);
}
if (sce06 == "Y")//sce06为Y时,为再次阅读,调用ydjl更改阅读次数和最后阅读时间.
{
message gjl = new message();
gjl.ydjl(sce, sce04);
}
Response.Redirect("readrecmsg.aspx?sce01=" + sce + ""); //将文件id传递readrecmsg.aspx页面,然后再在该页面查看通过该ID查看具体的文件内容
}
else
{
Response.Write("<script>alert('请选择要查看的通知!!')</script>");
Response.Write("<script>history.go(-1)</script>");
}
}
<asp:TemplateField HeaderText="标题">
<ItemTemplate>
<asp:Button ID="BtnBlackList" runat="server" Text="<%# Eval("scb04") %>" CommandName="DoThisMethod"
CommandArgument='<%# Eval("scb04") %>' />
</ItemTemplate>
</asp:TemplateField>
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "DoThisMethod")
{
///把你的后台代码放入里面
}
}