
后台:
using System;
using SystemCollectionsGeneric;
using SystemLinq;
using SystemWeb;
using SystemWebUI;
using SystemWebUIWebControls;
using SystemData;
using JHGameServiceLibraryBll;
using JHGameServiceLibraryModel;
using SystemDataSqlClient;
using JHGameServiceLibrary;
public partial class Manage_Examin_FillBlankManage : SystemWebUIPage
{
private int moduleid = 12;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (thisSession["UserName"] == null)
{
ResponseWrite(" <script type=text/javascript> alert('您没有登录或登录超时,请重新登录!');windowtopopener=null; windowtopclose(1);windowopen('//Loginaspx'); </script> ");
}
else
{
thisform1Visible = false;
Authority(moduleid);
}
Bind();
Bind1();
SessionRemove("newdb");
}
}
public void Authority(int moduleid)
{
Userinfo users = new Userinfo();
UserinfoBll usersbll = new UserinfoBll();
string UserName = Session["UserName"]ToString();
users = usersbllGetModelByName(UserName);
int uid = usersid;
UserRole usersrole = new UserRole();
UserRoleBll usersrolebll = new UserRoleBll();
usersrole = usersrolebllGetModelByUser(uid);
if (usersrole == null)
{
ResponseWrite("<script> alert('您暂无该权限!');location='firstWebaspx';</script>");
}
else
{
string rid = usersroleurroleidToString();
RoleuserAuth roleuAuth = new RoleuserAuth();
RoleuserAuthBll roleuAuthBll = new RoleuserAuthBll();
roleuAuth = roleuAuthBllGetModelById(ConvertToInt32(rid), moduleid);
if (roleuAuth == null)
{
ResponseWrite("<script> alert('您暂无该权限!');location='firstWebaspx';</script>");
}
else
{
string flag = roleuAuthflagToString();
if (flagEquals("0"))
{
thisform1Visible = true;
Bind();
}
else
{
ResponseWrite("<script> alert('您暂无该权限!');location='firstWebaspx';</script>");
}
}
}
}
FillBlankProblem fillbleanproblem = new FillBlankProblem();
FillBlankProblemBll fillbleanproblemBll = new FillBlankProblemBll();
public void Bind()
{
DataSet da = fillbleanproblemBllGets();
daAcceptChanges();
thisGvExaminDataSource = da;
thisGvExaminDataBind();
thisddlCurrentPageItemsClear();
for (int i = 1; i <= thisGvExaminPageCount; i++)
{
thisddlCurrentPageItemsAdd(iToString());
}
thisddlCurrentPageSelectedIndex = thisGvExaminPageIndex;
if (daTables[0]RowsCount == 0)
{
thisnotxtText = "没有相关数据!";
}
}
public void Bind1()
{
CourseBll courseBll = new CourseBll();
DataSet da = courseBllGets();
thisddlCourseDataSource = da;
ddlCourseDataValueField = "ID";
ddlCourseDataTextField = "Name";
ddlCourseDataBind();
ddlCourseItemsInsert(0, new ListItem("--请选择--", ""));
}
protected void ddlCourse_SelectedIndexChanged(object sender, EventArgs e)
{
DataSet res;
string id = thisddlCourseSelectedValue;
if (thisddlCourseSelectedIndex == 0)
{
res = fillbleanproblemBllGets();
}
else
{
res = fillbleanproblemBllGetByID(intParse(id));
}
thisGvExaminDataSource = res;
thisGvExaminDataBind();
string newdb = "123";
SessionAdd("newdb", newdb);
thisddlCurrentPageItemsClear();
for (int i = 1; i <= thisGvExaminPageCount; i++)
{
thisddlCurrentPageItemsAdd(iToString());
}
if (thisGvExaminRowsCount != 0)
{
thisddlCurrentPageSelectedIndex = thisGvExaminPageIndex;
}
else
{
thisnotxtText = "没有相关数据!";
}
}
protected void GvExamin_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GvExaminPageIndex = eNewPageIndex;
GvExaminDataBind();
Bind();
}
protected void GvExamin_RowDataBound(object sender, GridViewRowEventArgs e)
{
thislblCurrentPageText = stringFormat("当前第{0}页/总共{1}页", thisGvExaminPageIndex + 1, thisGvExaminPageCount);
//遍历所有行设置边框样式
foreach (TableCell tc in eRowCells)
{
tcAttributes["style"] = "border-color:Black";
}
//用索引来取得编号
if (eRowRowIndex != -1)
{
int id = GvExaminPageIndex GvExaminPageSize + eRowRowIndex + 1;
eRowCells[0]Text = idToString();
}
if (eRowRowType == DataControlRowTypeDataRow)
{
//鼠标移动到每项时颜色交替效果
eRowAttributesAdd("OnMouseOut", "thisstylebackgroundColor='White';thisstylecolor='#003399'");
eRowAttributesAdd("OnMouseOver", "thisstylebackgroundColor='#bfe2ff';thisstylecolor='#8C4510'");
eRowAttributes["style"] = "Cursor:hand";
}
//如果是绑定数据行
if (eRowRowType == DataControlRowTypeDataRow)
{
if (eRowRowState == DataControlRowStateNormal || eRowRowState == DataControlRowStateAlternate)
{
((LinkButton)eRowCells[6]Controls[0])AttributesAdd("onclick", "javascript:return confirm('你确认要删除吗')");
}
}
}
protected void ddlCurrentPage_SelectedIndexChanged(object sender, EventArgs e)
{
thisGvExaminPageIndex = thisddlCurrentPageSelectedIndex;
Bind();
if (Session["newdb"] == "123")
{
ddlCourse_SelectedIndexChanged(sender, e);
}
}
protected void lnkbtnFrist_Click(object sender, EventArgs e)
{
thisGvExaminPageIndex = 0;
Bind();
if (Session["newdb"] == "123")
{
ddlCourse_SelectedIndexChanged(sender, e);
}
}
protected void lnkbtnPre_Click(object sender, EventArgs e)
{
if (thisGvExaminPageIndex > 0)
{
thisGvExaminPageIndex = thisGvExaminPageIndex - 1;
Bind();
if (Session["newdb"] == "123")
{
ddlCourse_SelectedIndexChanged(sender, e);
}
}
}
protected void lnkbtnNext_Click(object sender, EventArgs e)
{
if (thisGvExaminPageIndex < thisGvExaminPageCount)
{
thisGvExaminPageIndex = thisGvExaminPageIndex + 1;
Bind();
if (Session["newdb"] == "123")
{
ddlCourse_SelectedIndexChanged(sender, e);
}
}
}
protected void lnkbtnLast_Click(object sender, EventArgs e)
{
thisGvExaminPageIndex = thisGvExaminPageCount;
Bind();
if (Session["newdb"] == "123")
{
ddlCourse_SelectedIndexChanged(sender, e);
}
}
protected void GvExamin_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int ID = ConvertToInt32(GvExaminDataKeys[eRowIndex]ValueToString());
int res = fillbleanproblemBllDelete(ID);
if (res > 0)
{
GvExaminEditIndex = -1;
Bind();
}
}
}
前台:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FillBlankManageaspxcs" Inherits="Manage_Examin_FillBlankManage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 10 Transitional//EN" ">
--前台页面:
--解释:
--DataKeyNames:字段名,一般绑定为 ID,用于后台获取ID
--OnRowCommand:GridView 定义行事件
--OnRowEditing:GridView 编辑事件
--OnRowUpdating:GridView 更新事件
--OnRowCancelingEdit:GridView 取消事件
<asp:GridView ID="gvException" runat="server" CssClass="DataGrid_Container" AutoGenerateColumns="False" DataKeyNames="id,ExceptionNumber" OnRowCommand="gvException_RowCommand" OnRowEditing="gvException_RowEditing" OnRowUpdating="gvException_RowUpdating"
OnRowCancelingEdit="gvException_RowCancelingEdit" >
<Columns>
<asp:BoundField DataField="number" HeaderText="号码" SortExpression="ExceptionNumber" />
<asp:CommandField HeaderText="修改" ItemStyle-Width="80" EditText="修改" ShowEditButton="True">
<ItemStyle Width="80px"></ItemStyle>
</asp:CommandField>
<asp:TemplateField ItemStyle-Width="80">
<HeaderTemplate>
删除</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="lbDelete" runat="server" ForeColor="Green" Text="删除" CommandName="DelNums"
CommandArgument="<%# ((GridViewRow) Container)RowIndex %>" OnClientClick="return confirm('确认要删除此行信息吗?')" />
</ItemTemplate>
<ItemStyle Width="80px"></ItemStyle>
</asp:TemplateField>
</Columns>
</asp:GridView>
--后台代码:
#region 删除 *** 作
/// <summary>
/// 行事件
/// </summary>
protected void gvException_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (eCommandNameToLower() == "delnums") //执行当前点击删除事件
{
//当前点击删除行的行号
int row = ConvertToInt32(eCommandArgumentToString());
//获取id
int id= gvExceptionDataKeys[row]["id"]ToString();
//执行SQL删除方法
if (执行失败)
{
ScriptManagerRegisterStartupScript(this, thisGetType(), "str", "<script>javascript:alert('删除失败!');</script>", false);
return;//退出方法
}
else//执行成功
{
ScriptManagerRegisterStartupScript(this, thisGetType(), "str", "<script>javascript:alert('删除成功!');</script>", false);
//成功重新绑定数据
//gvExceptionBind();
}
}
}
#endregion 删除 *** 作
#region 编辑 *** 作
/// <summary>
/// 编辑
/// </summary>
protected void gvException_RowEditing(object sender, GridViewEditEventArgs e)
{
//创建一个编辑控件
gvExceptionEditIndex = eNewEditIndex;
//gvExceptionBind();//重新绑定数据
}
/// <summary>
/// 更新按钮事件
/// </summary>
protected void gvException_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//获得 ID
int id = ConvertToInt32(gvExceptionDataKeys[eRowIndex]["id"]ToString());
//执行更新方法
if (更新失败)
{
ScriptManagerRegisterStartupScript(this, thisGetType(), "str", "<script>javascript:alert('更新失败!');</script>", false);
return;//退出方法
}
else//更新成功
{
ScriptManagerRegisterStartupScript(this, thisGetType(), "str", "<script>javascript:alert('更新成功!');</script>", false);
//成功重新绑定数据
//gvExceptionBind();
}
}
/// <summary>
/// 取消事件
/// </summary>
protected void gvException_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
//撤销编辑控件:为-1 是微软规定的
gvExceptionEditIndex = -1;
//gvExceptionBind();//重新绑定数据
}
#endregion
代码很多、希望你能看的懂,祝你好运^^
以上就是关于我用了Gridview,也绑定了数据库,但不知道该怎样在后台写代码全部的内容,包括:我用了Gridview,也绑定了数据库,但不知道该怎样在后台写代码、关于ASP.NET后台代码访问数据库(C#)SQLTransation的问题、用GridView自带删除修改功能删除修改数据库怎么做,后台代码怎么写等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)