gridview编辑,如何设置当某些时候让gridview中修改不可以点击呀
本文目录索引
- 1,如何设置当某些时候让gridview中修改不可以点击呀???
- 2,如何实现设置GridView单元格的值
- 3,gridview数据如何导入到Excell
- 4,C#中如何实现从 excel导入数据,并绑定到gridview上?
- 5,C# Asp.Net中gridview中自带的删除按钮怎么用
- 6,asp.net中GridView的删除、编辑,怎么实现
- 7,asp.net Gridview中点击编辑,在新页面打开进行编辑,求具体代码!
- 8,Asp.net GridView点击编辑后,编辑框显示原数据方法?
- 9,asp.net gridview 点了编辑不处于编辑状态
1,如何设置当某些时候让gridview中修改不可以点击呀???
<asp:LinkButton ID="LinkButton2" runat="server" Enabled="false" CausesValidation="False" CommandName="Update"
Text="修改">
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
OnClientClick='return confirm("您真的要删除这条记录吗?若执行此操作,项目涉及的月报及年度信息将会同时删除!")' Text="删除">
2,如何实现设置GridView单元格的值
public void GridViewBind()//gridvie数据绑定方法
{
//实例化SqlConnection对象
SqlConnection sqlCon = new SqlConnection();
//实例化SqlConnection对象连接数据库的字符串
sqlCon.ConnectionString = "server=.;uid=sa;pwd=;database=SearchDB";
//定义SQL语句
string SqlStr = "select * from Discussion";
//实例化SqlDataAdapter对象
SqlDataAdapter da = new SqlDataAdapter(SqlStr, sqlCon);
//实例化数据集DataSet
DataSet ds = new DataSet();
da.Fill(ds, "Discussion");
//绑定DataList控件
GridView1.DataSource = ds;//设置数据源,用于填充控件中的项的值列表
GridView1.DataBind();//将控件及其所有子控件绑定到指定的数据源
}
获取你查询的值!使用select 字段 from 表查询表中的数据,然后重新填充 GridView。
3,gridview数据如何导入到Excell
//GridView重写
public override void VerifyRenderingInServerForm(Control control)
{
// Confirms that an HtmlForm control is rendered for
}
//导入Excel方法
private void ExportDataGrid(string FileType, string FileName)
{
Response.Charset = "UTF8";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8));
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
GridView1.RenderControl(hw); //GridView1是GridView控件名,也可以是其他数据绑定控件
Response.Write(tw.ToString());
Response.End();
}
//导入Excel按钮事件
protected void Button3_Click(object sender, EventArgs e)
{
ExportDataGrid("application/ms-excel", "库存表.xlc");
}
绝对能用
4,C#中如何实现从 excel导入数据,并绑定到gridview上?
我的例子在Windows应用程序(C#)上经过了测试: string xlsFilePath = "G:\\Book1.xls"; string connectionString; connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + xlsFilePath + ";Extended Properties='Excel 8.0;HDR=False;IMEX=1'"; OleDbConnection conn = new OleDbConnection(connectionString); String strQuery = "SELECT * FROM [Sheet1$]"; //可以更改工作表名称 OleDbDataAdapter da = new OleDbDataAdapter(strQuery, conn); DataSet ds = new DataSet(); da.Fill(ds, "Sheet1"); DataTable dt = ds.Tables[0]; dataGridView1.DataSource = dt; conn.Close(); 运行效果:
5,C# Asp.Net中gridview中自带的删除按钮怎么用
楼主你好: GridView选中,编辑,取消,删除: 效果图: 后台代码: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 { SqlConnection sqlcon; SqlCommand sqlcom; string strCon = "Data Source=(local);Database=数据库名;Uid=帐号;Pwd=密码"; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { bind(); } } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; bind(); } //删除 protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { string sqlstr = "delete from 表 where id='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'"; sqlcon = new SqlConnection(strCon); sqlcom = new SqlCommand(sqlstr,sqlcon); sqlcon.Open(); sqlcom.ExecuteNonQuery(); sqlcon.Close(); bind(); } //更新 protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { sqlcon = new SqlConnection(strCon); string sqlstr = "update 表 set 字段1='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + "',字段2='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim() + "',字段3='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim() + "' where id='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'"; sqlcom=new SqlCommand(sqlstr,sqlcon); sqlcon.Open(); sqlcom.ExecuteNonQuery(); sqlcon.Close(); GridView1.EditIndex = -1; bind(); } //取消 protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { GridView1.EditIndex = -1; bind(); } //绑定 public void bind() { string sqlstr = "select * from 表"; sqlcon = new SqlConnection(strCon); SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon); DataSet myds = new DataSet(); sqlcon.Open(); myda.Fill(myds, "表"); GridView1.DataSource = myds; GridView1.DataKeyNames = new string[] { "id" };//主键 GridView1.DataBind(); sqlcon.Close(); }} 前台主要代码: ... ... 希望对你有帮助,望采纳,谢谢
6,asp.net中GridView的删除、编辑,怎么实现
在GridView的属性中有一个闪电符号的按钮
你点一下就会看到很多事件,然后分别点RowDeleting(点击某一行的删除按钮时发生该事件)
RowUpdating点更新的事件
RowEditing点编辑的事件
RowCancelingEdit点取消的事件
你就可以分别在这些事件中写你要执行的代码
最后不要忘记在更新和取消的事件中写GridView1.EditIndex = -1;来设置控件的编辑项的索引为-1
7,asp.net Gridview中点击编辑,在新页面打开进行编辑,求具体代码!
点击的时候跳转页面,用button linkbutton 都可以
最主要的是获取当前行的ID
例如: int id = Convert.ToInt32(this.GridView1.Rows[e.RowIndex].Cells[0].Text.ToString());
当你获取到当前行的ID 那么更新数据就很容易
如:点击按钮的时候跳转
int id = Convert.ToInt32(this.GridView1.Rows[e.RowIndex].Cells[0].Text.ToString());
Response.Redirect("page2.aspx?id="+id);
在page2页面里接收 id
string id=Request.QueryString("id");
用id去查询数据库 然后赋值给textbox就可以了
8,Asp.net GridView点击编辑后,编辑框显示原数据方法?
'> '> '> '> '> ' /> 是不是这种?? 那个ddlBind()是你后台代码的一个方法
9,asp.net gridview 点了编辑不处于编辑状态
首先 我看见你的
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
EnableModelValidation="True" onrowediting="GridView1_RowEditing" PageIndex="10">
GridView列表,只有处理命令列,没有其他的数据列!不知道你要编辑什么东西 呵呵!
第一 GridView要想使用自带的编辑、更新、删除、等功能时,你的所有数据展现列必须是模板列,也就是 TemplateField 类型的,
只有设置成为TemplateField 类型的列,你才可以在GridView的编辑模板中才可以看到,每一个TemplateField 都有一个ItemTemplate和EditItemTemplate,这个ItemTemplate项里有一个Label控件,它是用来显示这列绑定的数据的。而EditItemTemplate里面有一个TextBox控件,其实你点击“编辑”展现的其实就是这个TextBox控件。
你的GridView里面没有一个TemplateField 类型的列,怎么编辑呀,呵呵