我经常用到的代码

gridview:

Label lbs = (Label)GridView1.Rows[i].FindControl("Label2");
            string bn = (lbs.Text).ToString();
            TextBox tb1 = (TextBox)GridView1.Rows[i].FindControl("TextBox1");
            int count = Int32.Parse(tb1.Text);

图片上传:

 

 protected void Button1_Click(object sender, EventArgs e)
    {
        string bookname=bookTxt.Text;
        decimal price=Convert.ToDecimal(priceTxt.Text);
        int count=Convert.ToInt32(countTxt.Text);
        int ID=DropDownList1.SelectedIndex+1;
        string Details = TextBox1.Text;
        try
        {
            ImageUpload1.Visible = true;
            if (ImageUpload1.PostedFile.FileName == "")
            {
                image.Text = "要上传的文件不允许为空";
                return;
            }
            else
            {
                string filePath = ImageUpload1.PostedFile.FileName;
                string fileName = filePath.Substring(filePath.LastIndexOf("\\") + 1);
                string serverPath = Server.MapPath(@"~\Images\") + fileName;
                string relativepath = @"~\Images\" + fileName;
                ImageUpload1.PostedFile.SaveAs(serverPath);
                image.Text="上传成功";
                Image1.ImageUrl=relativepath;
                DB a = new DB();
                a.addBook(bookname, relativepath, price, ID, count,Details);
            }

        }
        catch (Exception err)
        {
            image.Text = err.ToString();
        }

Datalist分页:

 

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;

class DataList分页
{
  
protected void Page_Load(object sender, EventArgs e)
   
{
  
if (!Page.IsPostBack)
  
{
     FillData();
         }
  }
 
static PagedDataSource Pds;
  
void FillData()
   
{
         SqlConnection Conn =
new SqlConnection("Data Source=192.168.1.30;database=Ticket_Info_Data;UID=sa;Password=sa;Persist Security Info=True;");
         Conn.Open();
         SqlDataAdapter Sda =
new SqlDataAdapter("select * from DomesticFlight", Conn);
         DataSet Ds =
new DataSet();
         Sda.Fill(Ds);
         Pds =
new PagedDataSource();
         Pds.DataSource = Ds.Tables[0].DefaultView;
         Pds.AllowPaging =
true;
         Pds.PageSize = 6;
        
this.DataList1.DataSource = Pds;
        
this.DataList1.DataBind();
         Conn.Close();
     }
//下一页
 protected void LinkButton2_Click(object sender, EventArgs e)
 
{
         Pds.CurrentPageIndex++;
        
this.DataList1.DataSource = Pds;
        
this.DataList1.DataBind();
     }
//上一页
    protected void LinkButton1_Click(object sender, EventArgs e)
   
{
         Pds.CurrentPageIndex--;
        
this.DataList1.DataSource = Pds;
        
this.DataList1.DataBind();
     }
}

 

datatable合并:

 

 string Book_Id= Request.QueryString.Get("Book_Id");
                      dt.Add(Book_Id);  

            DataTable tablegetname = new DataTable();
            DataTable table = new DataTable();
            BShowBookShop bsb = new BShowBookShop();
            DataTable[] tables = new DataTable[dt.Count];

            tablegetname = bsb.BLL_SelectBook(Book_Id);
            for (int j = 0; j < tablegetname.Columns.Count; j++)
            {
                table.Columns.Add(tablegetname.Columns[j].ColumnName);

            } 

            object[] obj = new object[table.Columns.Count];
            for (int i = 0; i < dt.Count; i++)
            {
                tables[i] = bsb.BLL_SelectBook(dt[i]);
                for (int j = 0; j < tables[i].Rows.Count; j++)
                {
                    tables[i].Rows[j].ItemArray.CopyTo(obj,0);
                    table.Rows.Add(obj);

                }
            }

            GridView1.DataSource = table;
            GridView1.DataBind();

 GridView 72绝技:http://blog.csdn.net/21aspnet/archive/2007/03/25/1540301.aspx

 

 

<script language="javascript" type="text/javascript">
// 验证用户或密码
function Validate()
{
 if (document.all('txtUserName').value == "")
 {
  alert('用户名不能为空!');
  document.all('txtUserName').focus();
  return false;
 } 
 else if (document.all('txtPassword').value == "")
 {
  alert('密码不能为空!');
  document.all('txtPassword').focus();
  return false;
 }
 
    if(document.all.chkRememberMe.checked)
    { 
        //过期时间处理
        var expdate = new Date();
        expdate.setTime(expdate.getTime()+(365*24*60*60*1000));
        SetCookie("UserName", document.all.txtUserName.value, expdate);
        SetCookie("PassWord", document.all.txtPassword.value, expdate);
    }else{
        DeleteCookie("UserName");
        DeleteCookie("PassWord");
    }     
   
 return true;

function RemeberInfo()
{
    //get cookie
    //debugger;
    var userCookie = GetCookie("UserName");
    var passCookie = GetCookie("PassWord");

    if((userCookie==null) || (userCookie=="") || (passCookie==null) || (passCookie=="")){
        userCookie = "";
        passCookie = "";
        document.all.chkRememberMe.checked = false;
    }else{
        document.all.chkRememberMe.checked = true;
    }

    document.getElementById("txtUserName").value = userCookie;
    document.all.txtPassword.value = passCookie;
    document.all.btnLogion.focus();
}
</script>

 

 

    <script language="Javascript" src="Scripts/common.js" type="text/javascript" charset="gb2312"></script>
    <script language="javascript" type="text/javascript">
    // 初始化
  function Init()
  {           
   document.getElementById("txtUserName").focus();   
   
   RemeberInfo();
  }  
  
   
  
  // 打开一个新窗口并最大化显示
  function openWindow(url)
  {       
   // 设置窗口的属性
   var top  = 0;
   var left = 0;
   var width = screen.availWidth  - 10;
   var height = screen.availHeight - 30;    
   
   // 关闭登录窗口
   window.opener = null;
   window.open("","_self");
   window.close();
   
   // 打开页面
   window.open(url,"","scrollbars=yes,status=yes,toolbar=no,menubar=no,location=no,width=" + width +",height=" + height +",top="+ top +",left="+ left);
  }
   //删除Cookies
        function delCookie()
        {
            DeleteCookie("UserName");
            DeleteCookie("PassWord");
        }
    </script>

 

页面中直接使用js:

else
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "Info", "<script>alert('对不起,您还没有登录或操作超时!');window.close();window.open('Default.aspx');</script>");
        }

posted @ 2008-09-12 16:48  IT-CEO  阅读(255)  评论(0编辑  收藏  举报