introductionlist.aspx.cs

来自「一个简单的Demo」· CS 代码 · 共 103 行

CS
103
字号
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Surance.DB4ODAL;
using Surance.DBUtility;
using Db4objects.Db4o;

public partial class IntroductionList : System.Web.UI.Page
{
    private string editUrl = "IntroductionUpdate.aspx?Title=";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGrid();
        }
    }

    private void BindGrid()
    {   IObjectContainer db = DB4OHelper.DB;
        try
        {
            
            Introduction intro = new Introduction(db);
            GridView1.DataSource = intro.GetAll();
            GridView1.DataBind();
        }
        catch
        {

        }
        finally
        {
            db.Close();
        }

    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int index = Convert.ToInt32(e.CommandArgument.ToString().Trim());
        string title = GridView1.Rows[index].Cells[0].Text.Trim();
        switch (e.CommandName)
        {
            case "Edit":
                {
                    Response.Redirect(editUrl + title);
                    break;
                }
            case "Del":
                {
                    Del(index,title);
                    break;
                }
        }
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.RowIndex > -1)
            {
                LinkButton b = (LinkButton)e.Row.Cells[5].Controls[0];
                b.Attributes.Add("onClick", "javascript:return confirm('Are you sure to delete?');");

                
            }
        }
    }
    private void Del(int index, string title)
    {
        

        IObjectContainer db = DB4OHelper.DB;
        Introduction intro = new Introduction(db);
        // intro.Title = title;
        try
        {
            Introduction intro2 = intro.GetOne(title);
            if (intro2 != null)
            {
                intro.Del(intro2);
            }
        }
        catch
        {
        }
        finally
        {
            db.Close();
        }
        BindGrid();
    }


}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?