posts - 21,  comments - 1,  trackbacks - 0
aspx网页代码:
<asp:DataList ID="DataList1" runat="server" DataKeyField ="ProductKey" 
        CaptionAlign
="Bottom" CellPadding="4" EnableTheming="True" 
        ForeColor
="#333333" 
        onselectedindexchanged
="DataList1_SelectedIndexChanged" RepeatColumns="4" 
        RepeatDirection
="Horizontal" oncancelcommand="DataList1_CancelCommand" 
        ondeletecommand
="DataList1_DeleteCommand" 
        oneditcommand
="DataList1_EditCommand" ondatabinding="DataList1_DataBinding" 
        onitemcreated
="DataList1_ItemCreated" 
        onupdatecommand
="DataList1_UpdateCommand" Font-Bold="False" Font-Italic="False" 
        Font
-Overline="False" Font-Strikeout="False" Font-Underline="False" 
        
>
        
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        
<AlternatingItemStyle BackColor="White" 
            ForeColor
="#284775" />
        
<ItemStyle BackColor="#F7F6F3" 
            ForeColor
="#333333" />
        
<EditItemTemplate>
            序号:
<asp:TextBox ID="textnum" runat="server" Text='<%# Eval("ProductKey") %>'></asp:TextBox>
            
<br />
            时间:
<asp:TextBox ID="texttime" runat="server" 
                Text
='<%# Eval("ProductAlternateKey") %>'></asp:TextBox>
            
<br />
            
<asp:LinkButton ID="savebtn" runat="server" CommandName="update">保存</asp:LinkButton>
            
&nbsp;
            
<asp:LinkButton ID="LinkButton4" runat="server" CommandName="cancel">取消</asp:LinkButton>
        
</EditItemTemplate>
        
<SelectedItemStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        
<HeaderTemplate>
            演示头模板
        
</HeaderTemplate>
        
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        
<FooterTemplate>
            脚模板
        
</FooterTemplate>
        
<SelectedItemTemplate > 序号:<asp:Label ID="num" runat="server" Text='<%# Eval("ProductKey") %>'></asp:Label>
            
<br />
            时间:
<asp:Label ID="time" runat="server" 
                Text
='<%# Eval("ProductAlternateKey") %>'></asp:Label>
            
<br />
            数字:
<asp:Label ID="Label3" runat="server" Text='<%# Eval("ReorderPoint") %>'></asp:Label>
            
<br /></SelectedItemTemplate>
        
<ItemTemplate>
            序号:
<asp:Label ID="num" runat="server" Text='<%# Eval("ProductKey") %>'></asp:Label>
            
<br />
            时间:
<asp:Label ID="time" runat="server" 
                Text
='<%# Eval("ProductAlternateKey") %>'></asp:Label>
            
<br />
            
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="edit">修改</asp:LinkButton>
            
&nbsp;&nbsp;
            
<asp:LinkButton ID="delebtn" runat="server" CommandName="delete">删除</asp:LinkButton>
            
&nbsp;
        
</ItemTemplate>
    
</asp:DataList>
cs代码文件:
using System;
using System.Data;
using System.Configuration;
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 System.Data.SqlClient;



public partial class _Default : System.Web.UI.Page
{
    
private void  con()
    
{
        
string connstring = ConfigurationManager.ConnectionStrings["AdventureWorksDWConnectionString"].ConnectionString;
        SqlConnection con 
= new SqlConnection(connstring);
        SqlConnection conn 
= new SqlConnection();
        DataSet ds 
= new DataSet();
        SqlDataAdapter sda 
= new SqlDataAdapter("select * from DimProduct", con);
        sda.Fill(ds, 
"name");
        
//SqlDataAdapter sda2 = new SqlDataAdapter("select * from ProspectiveBuyer", con);
        
//sda2.Fill(ds, "title");
        PagedDataSource pds = new PagedDataSource();
        pds.DataSource 
= ds.Tables["name"].DefaultView;
        
//PagedDataSource aa = new PagedDataSource();
        pds.AllowPaging = true;//允许分页
  DataList1.DataSource = pds;
        DataList1.DataBind();

    }


    
protected void Page_Load(object sender, EventArgs e)
    
{
        
if (!IsPostBack)
        
{
            con();
        }


    }

    
protected void DataList1_EditCommand(object source, DataListCommandEventArgs e)
    
{
       
        DataList1.EditItemIndex 
= e.Item.ItemIndex;
        con();

    }

    
protected void DataList1_CancelCommand(object source, DataListCommandEventArgs e)
    
{
        DataList1.EditItemIndex 
= -1;
        con();
    }

    
protected void DataList1_DeleteCommand(object source, DataListCommandEventArgs e)
    
{
        
string id = Convert.ToString(DataList1.DataKeys[e.Item.ItemIndex]);
        
string sqlcmd = "delete from DimProduct where ProductKey='" + id + "'";
            
string connstring = ConfigurationManager.ConnectionStrings["AdventureWorksDWConnectionString"].ConnectionString;
            SqlConnection conn 
= new SqlConnection(connstring);
            SqlCommand cmd 
= new SqlCommand(sqlcmd, conn);
            conn.Open();
            cmd.ExecuteNonQuery();
            con();
      }

    
protected void DataList1_DataBinding(object sender, EventArgs e)
    
{

    }

    
protected void DataList1_ItemCreated(object sender, DataListItemEventArgs e)
    
{

        
switch (e.Item.ItemType)
        
{
            
case ListItemType.Item:
            
case ListItemType.AlternatingItem:
            
case ListItemType.SelectedItem:
                ((LinkButton)(e.Item.FindControl(
"delebtn"))).Attributes.Add(
                    
"onclick"" return confirm('你确认要删除');");
                
break;
        }

    }

    
protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
    
{
        
string id =Convert.ToString(DataList1.DataKeys[e.Item.ItemIndex]);
        
string num = ((TextBox)e.Item.FindControl("textnum")).Text;
        
string time = ((TextBox)e.Item.FindControl("texttime")).Text;
        
string sqlcmd = "update DimProduct set  ProductAlternateKey='" + time + "'where ProductKey='" + id + "'";
        
string connstring = ConfigurationManager.ConnectionStrings["AdventureWorksDWConnectionString"].ConnectionString;
        SqlConnection conn 
= new SqlConnection(connstring);
        SqlCommand cmd 
= new SqlCommand(sqlcmd, conn);
        conn.Open();
        cmd.ExecuteNonQuery();
        
this.DataList1.EditItemIndex = -1;
        con();
    }

}


posted on 2008-06-06 20:15 默默無語中 阅读(261) 评论(1)  编辑 收藏 网摘

FeedBack:
2008-07-19 11:27 | amalkk [未注册用户]
谢谢楼主分享
  回复  引用    

标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
Google站内搜索

相关文章:

相关链接:


 
<2008年7月>
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

21世纪一个人的成功不完全是你的才华 关键是你能够统占整合多少资源 然后达成一个预计的目标

 
点击这里给我发消息 
无限次升级的江民杀毒软件

与我联系

搜索

 

常用链接

留言簿

随笔档案(21)

文章档案(3)

相册

收藏夹(13)

一个收藏经典的站

最新随笔

最新评论

评论排行榜