我有一个gridview,但是上面没还有添加编译按钮,希望用户一进入页面就直接进入编辑状态,应该如何实现
解决方案 »
- aspnetpager 没有跳转
- aspx 页面的 Page 继承的是System.Web.UI 。 那用户控件的Page继承的是哪个?
- 请近来帮忙,谢谢!
- 求 SuperMap IS .NET 5.3.3 安装包
- 页面显示GIF图片的问题
- 一个RadioButton的问题
- 文件上传服务器无法正常运行问题
- DropDownList问题请教
- 我使用ActiveReports for .NET进行打印,我想让它横向打印,在打印对话框的布局里也进行了设置,可它总是纵向打印,这是为什么?
- 各位大哥大姐,大叔大爷救命了!该死的COM组件!这个问题被老总骂得狗血淋头,救救我吧!
- 急急急~~~~VS中所有 *.aspx文件在浏览器(内置浏览器、IE、firefox)中都无法浏览~~~望大家帮忙解决!
- windows2003+iis6.0 可以访问html文件但是asp和aspx的都不能访问
{
GridView1.EditIndex = ?;
}
我有4个字段,其中有2各需要编辑,没有多余的按钮,希望用户进入页面以后直接就可以对所有行中的那2列进行编辑。
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
GridLines="None" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="Wno" HeaderText="Wno" ReadOnly="True" />
<asp:BoundField DataField="Cname" HeaderText="Cname" />
<asp:BoundField DataField="Fname" HeaderText="Fname" />
<asp:BoundField DataField="Matter" HeaderText="Matter" />
<asp:CommandField HeaderText="选择" ShowSelectButton="True" />
<asp:CommandField HeaderText="编辑" ShowEditButton="True" />
<asp:CommandField HeaderText="删除" ShowDeleteButton="True" />
</Columns>
</asp:GridView>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
private void bind()
{
string sql = "select Wno,Cname,Fname,Matter from Cuser";
DataSet ds = new DataSet();
ds = Conn.getDataSet(sql);
GridView1.DataSource = ds.Tables[0];
GridView1.DataKeyNames = new string[] { "Wno" };
GridView1.DataBind();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
bind();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string sqlstr = "delete from Cuser where Wno='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
Conn.executeDML(sqlstr);
bind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
bind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string sqlstr = "update Cuser set Cname='"
+ ((DropDownList)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + "',Fname='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim() + "',Matter='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim() + "'where Wno='"
+ GridView1.Rows[e.RowIndex].Cells[0].Text.ToString().Trim() + "'";
Conn.executeDML(sqlstr);
GridView1.EditIndex = -1;
bind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[0].Text + "\"吗?')");
}
}
}可以参考下,有什么不对的再改改,没测试