用户登录  |  用户注册
首 页商业源码原创产品编程论坛
当前位置:PB创新网文章中心.Net

XML、DataSet、DataGrid结合写成广告管理程序

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2009-03-12 16:03:05
我们再来看看ASP.Net的源代码


<% @ Page Language="C#" ResponseEncoding="gb2312" %>
<% @ Import Namespace="System.Data" %>
<% @ Import Namespace="System.xml(标准化越来越近了)" %>
<% @ Import Namespace="System.IO" %>
<Script Language="C#" Runat="Server">
DataSet ds;        //定义公用的DataSet
DataView dv;  //定义公用的DataView
string SortField;
string sPath;
public void Page_Load(Object src,EventArgs e)
{
    if(State["adxml(标准化越来越近了)"]==null)
    {
        sPath = Server.MapPath(".") + "\\AdBanners\\ad_gb.xml(标准化越来越近了)";
        ds = new DataSet();
        ds.Readxml(标准化越来越近了)(sPath);
        State["adxml(标准化越来越近了)"] = ds;
    }
    else
    {
        ds = (DataSet)State["adxml(标准化越来越近了)"];
    }
    dv = ds.Tables[0].DefaultView;
    dv.Sort = "ImageUrl";

    if(!Page.IsPostBack)
    {
        CreateTable();
    }
}

//捆绑Binder
public void CreateTable()
{

    dgxml(标准化越来越近了).DataSource = dv;
    dgxml(标准化越来越近了).DataBind();
}

//翻页时
public void dgxml(标准化越来越近了)_Changed(Object sender,DataGridPageChangedEventArgs e)
{
    CreateTable();
}

//删除
public void DelItem(Object sender,DataGridCommandEventArgs e)
{
    if(((LinkButton)e.CommandSource).CommandName == "del")
    {
        //首先取得当前更新页的行数与CurrentPageIndex
        int CPI = (int)dgxml(标准化越来越近了).CurrentPageIndex;
        int EII = (int)e.Item.ItemIndex;
        int row = CPI*5+EII;

        lb.Text = row.ToString();

        //删除
        dv.Delete(row);

        dgxml(标准化越来越近了).EditItemIndex = -1;
        ds.Writexml(标准化越来越近了)(sPath);

        CreateTable();
    }
}

//取消
public void dgxml(标准化越来越近了)_Cancel(Object sender,DataGridCommandEventArgs e)
{
    dgxml(标准化越来越近了).EditItemIndex = -1;
    CreateTable();
}

//编辑
public void dgxml(标准化越来越近了)_Edit(Object sender,DataGridCommandEventArgs e)
{
    dgxml(标准化越来越近了).EditItemIndex = (int)e.Item.ItemIndex;
    CreateTable();
}

//更新
public void dgxml(标准化越来越近了)_Update(Object sender, DataGridCommandEventArgs e)
{
    try
    {
        //首先取得当前更新页的行数与CurrentPageIndex
        int CPI = (int)dgxml(标准化越来越近了).CurrentPageIndex;
        int EII = (int)e.Item.ItemIndex;
        int row = CPI*5+EII;
        //lb.Text = row.ToString();

        //取得各项值

        string ImageUrl         = ((TextBox)e.Item.Cells[2].Controls[0]).Text;
        string NavigateUrl        = ((TextBox)e.Item.Cells[3].Controls[0]).Text;
        string AlternateText  = ((TextBox)e.Item.Cells[4].Controls[0]).Text;
        string Keyword        = ((TextBox)e.Item.Cells[5].Controls[0]).Text;
        string Impressions        = ((TextBox)e.Item.Cells[6].Controls[0]).Text;

        dv.Delete(row);

        DataRow dr = ds.Tables[0].NewRow();
        dr[0] =    ImageUrl;
        dr[1] =    NavigateUrl;
        dr[2] =    AlternateText;
        dr[3] =    Keyword;
        dr[4] =    Impressions;
        ds.Tables[0].Rows.Add(dr);
        ds.Writexml(标准化越来越近了)(sPath);
    }
    catch(Exception ee)
    {
        lb.Text = ee.ToString();
    }

    dgxml(标准化越来越近了).EditItemIndex = -1;
    CreateTable();


}

public void PanelShow(Object sender,EventArgs e)
{
    AddItem.Visible = true;
}

public void AddItem_Click(Object sender,EventArgs e)
{
    DataRow dr = ds.Tables[0].NewRow();
    dr[0] =    mUrl.Text;
    dr[1] =    aUrl.Text;
    dr[2] =    mText.Text;
    dr[3] =    aKey.Text;
    dr[4] =    aTime.Text;
    ds.Tables[0].Rows.Add(dr);
    ds.Writexml(标准化越来越近了)(sPath);
    CreateTable();
    AddItem.Visible=false;
}
</script>
<html>
<head>
<title></title>
</head>
<body>
<form id="form1" runat="server">
asp:DataGrid id="dgxml(标准化越来越近了)" runat="server"
AllowPaging="True"
PageSize="10"
BorderColor="black"
BorderWidth="1"
CellPadding="3"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
PagerStyle-Mode="NumericPages"
PagerStyle-HorizontalAlign="Right"
PagerStyle-PrevPageText="前页"
PagerStyle-NextPageText="后页"
OnPageIndexChanged="dgxml(标准化越来越近了)_Changed"
OnEditCommand="dgxml(标准化越来越近了)_Edit"
OnCancelCommand="dgxml(标准化越来越近了)_Cancel"
OnUpdateCommand="dgxml(标准化越来越近了)_Update"
OnItemCommand="DelItem"
AutoGenerateColumns="false"

<property name="Columns">
    <asp:ButtonColumn HeaderText="删除" Text="删除" CommandName="del" />
   。糰sp:EditCommandColumn EditText="修改" CancelText="取消" UpdateText="更新" ItemStyle-Wrap="false" HeaderText="操作区" HeaderStyle-Wrap="false" />
    <asp:BoundColumn HeaderText="图片地址(相对)" SortField="ImageUrl" DataField="ImageUrl" />
    <asp:BoundColumn HeaderText="链接URL" SortField="NavigateUrl" DataField="NavigateUrl" />
    <asp:BoundColumn HeaderText="图片说明" SortField="AlternateText" DataField="AlternateText" />
    <asp:BoundColumn HeaderText="类别" SortField="Keyword" DataField="Keyword" />
    <asp:BoundColumn HeaderText="显示时间" SortField="Impressions" DataField="Impressions" />
</property>
</asp:DataGrid>
<hr>
asp:Button id="vi" Text="添加新项" runat="server"/>
<br>
asp:Panel id="AddItem" runat="server" Visible="false">
<table>
    <tr Bgcolor="#aaaadd"><td colspan=2>添加新的广告页面</td></tr>
    <tr>
        <td>广告图片URL:</td>
        <td><asp:TextBox id="mUrl" runat="server" Text="http://" /></td>
    </tr>
    <tr>
        <td>广告链接地址:</td>
        <td><asp:TextBox id="aUrl" runat="server" Text="http://" /></td>
    </tr>
    <tr>
        <td>图片说明:</td>
        <td><asp:TextBox id="mText" runat="server" /></td>
    </tr>
    <tr>
        <td>广告所属类别:</td>
        <td><asp:TextBox id="aKey" runat="server" /></td>
    </tr>
    <tr>
        <td>显示时间</td>
        <td><asp:TextBox id="aTime" runat="server" /></td>
    </tr>
    <tr><td>
   <asp:Button id="submit" Text="提交" runat="server" /></td></tr>
</table>
</asp:Panel>
asp:Label id="lb" runat="server" />
</form>
</body>
</html>

Tags:

作者:佚名

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论

栏目导航

本类热门阅览

相关文章

PB创新网ourmis.com】Copyright © 2000-2009 . All Rights Reserved .
页面执行时间:2,312.50000 毫秒
Email:ourmis@126.com QQ:2322888 蜀ICP备05006790号