我用GridView嵌套GridView,想法是运用父GridView的条件挑选子GridView,可是,第一个总是没有
发布网友
发布时间:2022-08-17 19:06
我来回答
共1个回答
热心网友
时间:2023-10-13 17:20
g System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using JH.Game.ServiceLibrary.Bll;
using JH.Game.ServiceLibrary.Model;
using System.Data.SqlClient;
using JH.Game.ServiceLibrary;
public partial class Manage_Examin_FillBlankManage : System.Web.UI.Page
{
private int moleid = 12;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (this.Session["UserName"] == null)
{
Response.Write(" <script type=text/javascript> alert('您没有登录或登录超时,请重新登录!');window.top.opener=null; window.top.close(1);window.open('../../Login.aspx'); </script> ");
}
else
{
this.form1.Visible = false;
Authority(moleid);
}
Bind();
Bind1();
Session.Remove("newdb");
}
}
public void Authority(int moleid)
{
Userinfo users = new Userinfo();
UserinfoBll usersbll = new UserinfoBll();
string UserName = Session["UserName"].ToString();
users = usersbll.GetModelByName(UserName);
int uid = users.id;
UserRole usersrole = new UserRole();
UserRoleBll usersrolebll = new UserRoleBll();
usersrole = usersrolebll.GetModelByUser(uid);
if (usersrole == null)
{
Response.Write("<script> alert('您暂无该权限!');location='firstWeb.aspx';</script>");
}
else
{
string rid = usersrole.urroleid.ToString();
RoleuserAuth roleuAuth = new RoleuserAuth();
RoleuserAuthBll roleuAuthBll = new RoleuserAuthBll();
roleuAuth = roleuAuthBll.GetModelById(Convert.ToInt32(rid), moleid);
if (roleuAuth == null)
{
Response.Write("<script> alert('您暂无该权限!');location='firstWeb.aspx';</script>");
}
else
{
string flag = roleuAuth.flag.ToString();
if (flag.Equals("0"))
{
this.form1.Visible = true;
Bind();
}
else
{
Response.Write("<script> alert('您暂无该权限!');location='firstWeb.aspx';</script>");
}
}
}
}
FillBlankProblem fillbleanproblem = new FillBlankProblem();
FillBlankProblemBll fillbleanproblemBll = new FillBlankProblemBll();
public void Bind()
{
DataSet da = fillbleanproblemBll.Gets();
da.AcceptChanges();
this.GvExamin.DataSource = da;
this.GvExamin.DataBind();
this.ddlCurrentPage.Items.Clear();
for (int i = 1; i <= this.GvExamin.PageCount; i++)
{
this.ddlCurrentPage.Items.Add(i.ToString());
}
this.ddlCurrentPage.SelectedIndex = this.GvExamin.PageIndex;
if (da.Tables[0].Rows.Count == 0)
{
this.notxt.Text = "没有相关数据!";
}
}
public void Bind1()
{
CourseBll courseBll = new CourseBll();
DataSet da = courseBll.Gets();
this.ddlCourse.DataSource = da;
ddlCourse.DataValueField = "ID";
ddlCourse.DataTextField = "Name";
ddlCourse.DataBind();
ddlCourse.Items.Insert(0, new ListItem("--请选择--", ""));
}
protected void ddlCourse_SelectedIndexChanged(object sender, EventArgs e)
{
DataSet res;
string id = this.ddlCourse.SelectedValue;
if (this.ddlCourse.SelectedIndex == 0)
{
res = fillbleanproblemBll.Gets();
}
else
{
res = fillbleanproblemBll.GetByID(int.Parse(id));
}
this.GvExamin.DataSource = res;
this.GvExamin.DataBind();
string newdb = "123";
Session.Add("newdb", newdb);
this.ddlCurrentPage.Items.Clear();
for (int i = 1; i <= this.GvExamin.PageCount; i++)
{
this.ddlCurrentPage.Items.Add(i.ToString());
}
if (this.GvExamin.Rows.Count != 0)
{
this.ddlCurrentPage.SelectedIndex = this.GvExamin.PageIndex;
}
else
{
this.notxt.Text = "没有相关数据!";
}
}
protected void GvExamin_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GvExamin.PageIndex = e.NewPageIndex;
GvExamin.DataBind();
Bind();
}
protected void GvExamin_RowDataBound(object sender, GridViewRowEventArgs e)
{
this.lblCurrentPage.Text = string.Format("当前第页/总共页", this.GvExamin.PageIndex + 1, this.GvExamin.PageCount);
//遍历所有行设置边框样式
foreach (TableCell tc in e.Row.Cells)
{
tc.Attributes["style"] = "border-color:Black";
}
//用索引来取得编号
if (e.Row.RowIndex != -1)
{
int id = GvExamin.PageIndex * GvExamin.PageSize + e.Row.RowIndex + 1;
e.Row.Cells[0].Text = id.ToString();
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标移动到每项时颜色交替效果
e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor='White';this.style.color='#003399'");
e.Row.Attributes.Add("OnMouseOver", "this.style.backgroundColor='#bfe2ff';this.style.color='#8C4510'");
e.Row.Attributes["style"] = "Cursor:hand";
}
//如果是绑定数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除吗?')");
}
}
}
protected void ddlCurrentPage_SelectedIndexChanged(object sender, EventArgs e)
{
this.GvExamin.PageIndex = this.ddlCurrentPage.SelectedIndex;
Bind();
if (Session["newdb"] == "123")
{
ddlCourse_SelectedIndexChanged(sender, e);
}
}
protected void lnkbtnFrist_Click(object sender, EventArgs e)
{
this.GvExamin.PageIndex = 0;
Bind();
if (Session["newdb"] == "123")
{
ddlCourse_SelectedIndexChanged(sender, e);
}
}
protected void lnkbtnPre_Click(object sender, EventArgs e)
{
if (this.GvExamin.PageIndex > 0)
{
this.GvExamin.PageIndex = this.GvExamin.PageIndex - 1;
Bind();
if (Session["newdb"] == "123")
{
ddlCourse_SelectedIndexChanged(sender, e);
}
}
}
protected void lnkbtnNext_Click(object sender, EventArgs e)
{
if (this.GvExamin.PageIndex < this.GvExamin.PageCount)
{
this.GvExamin.PageIndex = this.GvExamin.PageIndex + 1;
Bind();
if (Session["newdb"] == "123")
{
ddlCourse_SelectedIndexChanged(sender, e);
}
}
}
protected void lnkbtnLast_Click(object sender, EventArgs e)
{
this.GvExamin.PageIndex = this.GvExamin.PageCount;
Bind();
if (Session["newdb"] == "123")
{
ddlCourse_SelectedIndexChanged(sender, e);
}
}
protected void GvExamin_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int ID = Convert.ToInt32(GvExamin.DataKeys[e.RowIndex].Value.ToString());
int res = fillbleanproblemBll.Delete(ID);
if (res > 0)
{
GvExamin.EditIndex = -1;
Bind();
}
}
}
前台:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FillBlankManage.aspx.cs" Inherits="Manage_Examin_FillBlankManage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head id="Head1" runat="server">
<title>百问百答</title>
<link href="../Css/gr.css" rel="stylesheet" type="text/css" />
<link href="../Css/yui-datatable.css" rel="stylesheet" type="text/css" />
</head>
<body style="background-color:#bfe2ff">
<form id="form1" runat="server">
<div>
<table width ="99%">
<tr>
<td align="center" style=" height:30px; line-height:30px; font-size:15px; font-weight:bold; text-align:center">百问百答</td>
</tr>
<tr>
<td align ="left">
问题类型:<asp:DropDownList ID="ddlCourse" runat="server" AutoPostBack="True" onselectedindexchanged="ddlCourse_SelectedIndexChanged"
>
</asp:DropDownList>
  
</td>
</tr>
</table>
<asp:GridView ID="GvExamin" GridLines="None"
runat="server"
AutoGenerateColumns="False" Width="99%" AllowPaging="True"
CssClass="yui-datatable-theme"
DataKeyNames="ID"
PageSize="12" onpageindexchanging="GvExamin_PageIndexChanging"
onrowdatabound="GvExamin_RowDataBound"
onrowdeleting="GvExamin_RowDeleting" >
<RowStyle CssClass="data-row" />
<AlternatingRowStyle CssClass="alt-data-row" />
<Columns>
<asp:BoundField DataField="ID" HeaderText="序号" />
<asp:BoundField DataField="CourseID" HeaderText="所属" Visible="false" />
<asp:BoundField DataField="FrontTitle" HeaderText="问题" />
<asp:BoundField DataField="Answer" HeaderText="答案"/>
<asp:HyperLinkField DataNavigateUrlFormatString="FillBlankUpdate.aspx?ID="
HeaderText="详细信息" Text="详细信息" DataNavigateUrlFields="ID" />
<asp:HyperLinkField DataNavigateUrlFormatString="FillBlankUpdate.aspx?ID="
HeaderText="编辑" Text="编辑" DataNavigateUrlFields="ID" />
<asp:CommandField HeaderText="删除" ShowDeleteButton="True" />
</Columns>
<%--<FooterStyle CssClass="EG_FooterCSS" />
<SelectedRowStyle CssClass="GridSelectedItem" />
<AlternatingRowStyle CssClass="EG_AlternatingItemCSS" />
<HeaderStyle CssClass="EG_HeaderCSS" />
<RowStyle CssClass="EG_ItemCSS" />
<PagerStyle CssClass="GridViewPagerStyle" />--%>
<PagerSettings Visible="False" />
</asp:GridView>
<asp:Label ID ="notxt" runat="server"></asp:Label>
<br />
<asp:LinkButton ID="lnkbtnFrist" runat="server" onclick="lnkbtnFrist_Click" >首页</asp:LinkButton>
<asp:LinkButton ID="lnkbtnPre" runat="server" onclick="lnkbtnPre_Click" >上一页</asp:LinkButton>
<asp:Label ID="lblCurrentPage" runat="server"></asp:Label>
<asp:LinkButton ID="lnkbtnNext" runat="server" onclick="lnkbtnNext_Click" >下一页</asp:LinkButton>
<asp:LinkButton ID="lnkbtnLast" runat="server" onclick="lnkbtnLast_Click" >尾页</asp:LinkButton>
跳转到第<asp:DropDownList ID="ddlCurrentPage" runat="server" AutoPostBack="True" onselectedindexchanged="ddlCurrentPage_SelectedIndexChanged"
>
</asp:DropDownList>页
</div>
</form>
</body>
</html>