问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

我用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>
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
土地入股的定义 ups快递客服电话24小时 贷款记录在征信保留几年? 安徽徽商城有限公司公司简介 安徽省徽商集团新能源股份有限公司基本情况 安徽省徽商集团有限公司经营理念 2019哈尔滨煤气费怎么有税? 快手删除的作品如何恢复 体育理念体育理念 有关体育的格言和理念 关于GridView嵌套 使用360升级助手可以一键升级把电脑win7 32位的升级成win10 64位的吗?我是win7 怎么看水烧开了没 桌面的图标被用其他程序打开变成其他文件类型怎么变回来啊 急!急!急!文件类型被更改了怎么办? 求一个苹果手机上最好用的信用卡管理软件,之前用的卡牛,因为换苹果上权限太低,短信这些无法读取,导致 DNF漫游装备怎么弄 &#x200F; 水产养殖业用什么方法杀菌消毒? qq超市,有好的办法 让它 升级更快吗 卡坦精的基本特征 卡坦精是最甜的吗? 卡坦精的英文是什么? 房缺怎么办? 先天性房缺 心影膨大呈梨形 问题严重吗? 梨形心是种什么样的病 在建行申请了一张信用卡,卡刚发下来,想再申请一张建行的卡需要间隔多长时间吗? 地表最强175的小托马斯为什么决定退役? 含着眼泪对我倾吐衷肠说了很多心里话修改病句? 如何在一个手机上同时登录两个 求助,如何区分萨摩耶和赤狐? android ListView里面嵌套GridView问题 GridView中嵌套CheckBox,怎样才能当checkBox的被选中后从Button的click事件中去的被选中行的某一列值 android Listview嵌套Gridview 如何让Listview里的每个item项Gridview显示不同的数据 用C#写GridView嵌套,网上有很多例子,但是代码都不详细,本人新手,有没有这方面的大师能指点一下怎么做 梦见拿水桶从井里打水什么意思 玄奘成佛了吗 西游记中玄奘最后成的是什么佛 微信上现在遇到好多显示出来已经购双封的提示,已购双封,是什么意思嘛? 一个微信好友 买东西的 网名显示已开双封 举报护封是什么意思?谢谢 十二生肖那个属于有九条尾的动物? 农村占地补偿社保 农村土地征收后社保怎么补偿 全棉和纤维棉的区别 “我的城市我的梦”可以画什么? 节粮节水节电的横幅标语 学校节水节电节粮教育宣传标语 为什么我在酷狗音乐设置彩铃但是手机号码验证不了 手机酷狗进不了验证系统。 我的手机丢了,在酷狗里接收不到验证码怎么能解绑 祖母()地*着孙子的小脸蛋。 把"爱"字组词填在括号里。心爱疼爱? 课文《莲叶青青》中,摘抄描写祖母动作、语言、神态的句子。有什么?