高手帮忙看一下,GridView控件....我吐得了
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 System.Data.SqlClient;
public partial class GridView2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SetBind();
}
}
private void SetBind()
{
SqlConnection con = new SqlConnection("server=.;database=jinge;uid=sa;pwd=;");
SqlDataAdapter sda = new SqlDataAdapter("select * from News", con);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
sda.Fill(dt);
ds.Tables.Add(dt);
GridView1.DataSource = ds.Tables[0];
GridView1.DataKeyNames = new string[] { "n_id" };
GridView1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
SetBind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
SetBind();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
SetBind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string id = GridView1.DataKeys[0].Value.ToString();
[color=#FF0000]string n_id = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text.ToString().Trim(); //为什么我地方老是报错:指定的参数已超出有效值的范围。参数名: index[/color]
Response.Write(n_id);
}
}
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 System.Data.SqlClient;
public partial class GridView2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SetBind();
}
}
private void SetBind()
{
SqlConnection con = new SqlConnection("server=.;database=jinge;uid=sa;pwd=;");
SqlDataAdapter sda = new SqlDataAdapter("select * from News", con);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
sda.Fill(dt);
ds.Tables.Add(dt);
GridView1.DataSource = ds.Tables[0];
GridView1.DataKeyNames = new string[] { "n_id" };
GridView1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
SetBind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
SetBind();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
SetBind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string id = GridView1.DataKeys[0].Value.ToString();
[color=#FF0000]string n_id = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text.ToString().Trim(); //为什么我地方老是报错:指定的参数已超出有效值的范围。参数名: index[/color]
Response.Write(n_id);
}
}
...全文
相关推荐
Gridview控件的使用详解
GridView 控件的使用详解GridView 控件是 ASP.NET web 应用程序中最常用的数据_grid 控件之一,它提供了强大的功能来显示和编辑数据 Gridview 控件的使用是非常广泛的
GridView控件的简单使用
一、GridView控件简介GridView控件是一种强大的数据绑定控件,它可以动态地从数据库或其他数据源中获取数据,并将其以表格形式展现。
GridView控件应用十个经典实例
本文介绍了一个ASP.NET页面,该页面能够从数据库中检索商品信息,并通过GridView控件展示。页面加载时执行SQL查询,获取商品的ID、名称、介绍和价格等信息,并支持分页浏览。同时,页面还实现了
C#网格视图控件GridView的方法
### C#网格视图控件GridView的方法#### 网格视图控件GridView简介在C#开发中,尤其是在Windows Forms应用开发中,GridView 控件是一种常用的展示数据的方式,它能够有效地展示表格形式的数据
Android控件之GridView用法实例分析
在Android开发中,GridView是一个非常常用的控件,用于展示二维数据集,通常以网格的形式排列。


