关于DATALIST控件一个问题
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int begPage = 1;
try
{
begPage = Convert.ToInt32(Request.QueryString["p"]);
}
catch
{
}
if (begPage < 1)
{
begPage = 1;
}
int index = begPage - 1;
Binders(index);
hlPre.NavigateUrl = "Default.aspx?p=" + (begPage - 1);
hlNext.NavigateUrl = "Default.aspx?p=" + (begPage + 1);
lbMessage.Text = "当前为第" + begPage + "页";
if (!IsPostBack)
{
DataBind();
}
}
void Binders(int index)
{
PagedDataSource pds = new PagedDataSource();
pds.DataSource = SqlDataSource1.Select(DataSourceSelectArguments.Empty);
pds.AllowPaging = true;
pds.PageSize = 6;
pds.CurrentPageIndex = index;
DataList1.DataSource = pds;
}
protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
{
DataList1.DataBind();
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
switch (e.CommandName.ToLower())
{
case "unselect":
{
DataList1.SelectedIndex = -1;
DataList1.DataBind();
break;
}
default:
{
break;
}
}
}
protected void DataList1_EditCommand(object source, DataListCommandEventArgs e)
{
DataList1.EditItemIndex = e.Item.ItemIndex;
DataList1.DataBind();
}
protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
{
SqlDataSource1.UpdateParameters["Id"].DefaultValue = DataList1.DataKeys[e.Item.ItemIndex].ToString();
TextBox txt1 = (TextBox)e.Item.FindControl("txtDeptNo");
if (txt1 != null)
{
SqlDataSource1.UpdateParameters["DeptNo"].DefaultValue = txt1.Text;
}
TextBox txt2 = (TextBox)e.Item.FindControl("txtAssetCode");
if (txt2 != null)
{
SqlDataSource1.UpdateParameters["AssetCode"].DefaultValue = txt2.Text;
}
TextBox txt3 = (TextBox)e.Item.FindControl("txtDepreciationYear");
if (txt3 != null)
{
SqlDataSource1.UpdateParameters["DepreciationYear"].DefaultValue = txt3.Text;
}
TextBox txt4 = (TextBox)e.Item.FindControl("txtDepreciationMonth");
if (txt4 != null)
{