gridView编辑状态下某一列加入按钮
我想在gridView的编辑状态下在某一列加入一个Button,不知道具体如何做....请各位大侠指点大家没明白我的意思吗?...
我想在gridView的编辑状态下在某一列加入一个Button,不知道具体如何做....请各位大侠指点
大家没明白我的意思吗? 展开
大家没明白我的意思吗? 展开
5个回答
展开全部
不太明白,如果是覆盖在gridview上的话,可以用贞布局,放一个Button,先设为不可见,在需要加入是在设为可见,如果不是覆盖,而是在gridview 下面就不用贞布局,也是可见不可见的设置就可以解决了,不知道你是不是这个意思。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你想用那个button做提交按钮么??
gridView在编辑状态下会有一个确定按钮,为什么你还要单放button
gridView在编辑状态下会有一个确定按钮,为什么你还要单放button
追问
我有一列的数据是存入数据库图片的路径,我想在编辑状态下的时候再这一列上添加一个浏览的button,然后可以通过这个按钮来更改图片的路径。 具体和 fileUpLoad相似。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
前端:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
onrowediting="GridView1_RowEditing"
onrowcancelingedit="GridView1_RowCancelingEdit"
onrowdatabound="GridView1_RowDataBound" onrowupdating="GridView1_RowUpdating" >
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:TemplateField HeaderText="Photo">
<EditItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Bind("Photo") %>' />
<asp:FileUpload ID="FileUpload1" runat="server" />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblPhoto" runat="server" Text='<%# Bind("Photo") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="编辑">
<EditItemTemplate>
<asp:Button ID="btnUpdate" runat="server" Text="更新" CommandName="Update" />
<asp:Button ID="btnCancel" runat="server" Text="取消" CommandName="Cancel" />
</EditItemTemplate>
<ItemTemplate>
<asp:Button ID="btnEdit" runat="server" Text="编辑" CommandName="Edit"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
后端:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
private void BindData()
{
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(string));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Photo", typeof(string));
DataRow dr = dt.NewRow();
dr["ID"] = "1";
dr["Name"] = "张三";
dr["Photo"] = "D:\\a.jpg";
DataRow dr1 = dt.NewRow();
dr1["ID"] = "2";
dr1["Name"] = "李四";
dr1["Photo"] = "D:\\b.jpg";
dt.Rows.Add(dr);
dt.Rows.Add(dr1);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
BindData();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//更新数据的事在这里做
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
BindData();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && ((e.Row.RowState & DataControlRowState.Edit) > 0))
{
FileUpload fu = (FileUpload)e.Row.FindControl("FileUpload1");
Image image = (Image)e.Row.FindControl("Image1");
fu.Attributes.Add("onpropertychange", "javascript:document.getElementById('" + image.ClientID + "').src=document.getElementById('" + fu.ClientID + "').value");
}
}
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
onrowediting="GridView1_RowEditing"
onrowcancelingedit="GridView1_RowCancelingEdit"
onrowdatabound="GridView1_RowDataBound" onrowupdating="GridView1_RowUpdating" >
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:TemplateField HeaderText="Photo">
<EditItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Bind("Photo") %>' />
<asp:FileUpload ID="FileUpload1" runat="server" />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblPhoto" runat="server" Text='<%# Bind("Photo") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="编辑">
<EditItemTemplate>
<asp:Button ID="btnUpdate" runat="server" Text="更新" CommandName="Update" />
<asp:Button ID="btnCancel" runat="server" Text="取消" CommandName="Cancel" />
</EditItemTemplate>
<ItemTemplate>
<asp:Button ID="btnEdit" runat="server" Text="编辑" CommandName="Edit"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
后端:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
private void BindData()
{
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(string));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Photo", typeof(string));
DataRow dr = dt.NewRow();
dr["ID"] = "1";
dr["Name"] = "张三";
dr["Photo"] = "D:\\a.jpg";
DataRow dr1 = dt.NewRow();
dr1["ID"] = "2";
dr1["Name"] = "李四";
dr1["Photo"] = "D:\\b.jpg";
dt.Rows.Add(dr);
dt.Rows.Add(dr1);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
BindData();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//更新数据的事在这里做
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
BindData();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && ((e.Row.RowState & DataControlRowState.Edit) > 0))
{
FileUpload fu = (FileUpload)e.Row.FindControl("FileUpload1");
Image image = (Image)e.Row.FindControl("Image1");
fu.Attributes.Add("onpropertychange", "javascript:document.getElementById('" + image.ClientID + "').src=document.getElementById('" + fu.ClientID + "').value");
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
前端:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
onrowediting="GridView1_RowEditing"
onrowcancelingedit="GridView1_RowCancelingEdit"
onrowdatabound="GridView1_RowDataBound" onrowupdating="GridView1_RowUpdating" >
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:TemplateField HeaderText="Photo">
<EditItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Bind("Photo") %>' />
<asp:FileUpload ID="FileUpload1" runat="server" />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblPhoto" runat="server" Text='<%# Bind("Photo") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="编辑">
<EditItemTemplate>
<asp:Button ID="btnUpdate" runat="server" Text="更新" CommandName="Update" />
<asp:Button ID="btnCancel" runat="server" Text="取消" CommandName="Cancel" />
</EditItemTemplate>
<ItemTemplate>
<asp:Button ID="btnEdit" runat="server" Text="编辑" CommandName="Edit"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
后端:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
private void BindData()
{
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(string));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Photo", typeof(string));
DataRow dr = dt.NewRow();
dr["ID"] = "1";
dr["Name"] = "张三";
dr["Photo"] = "D:\\a.jpg";
DataRow dr1 = dt.NewRow();
dr1["ID"] = "2";
dr1["Name"] = "李四";
dr1["Photo"] = "D:\\b.jpg";
dt.Rows.Add(dr);
dt.Rows.Add(dr1);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
BindData();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//更新数据的事在这里做
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
BindData();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && ((e.Row.RowState & DataControlRowState.Edit) > 0))
{
FileUpload fu = (FileUpload)e.Row.FindControl("FileUpload1");
Image image = (Image)e.Row.FindControl("Image1");
fu.Attributes.Add("onpropertychange", "javascript:document.getElementById('" + image.ClientID + "').src=document.getElementById('" + fu.ClientID + "').value");
}
}
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
onrowediting="GridView1_RowEditing"
onrowcancelingedit="GridView1_RowCancelingEdit"
onrowdatabound="GridView1_RowDataBound" onrowupdating="GridView1_RowUpdating" >
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:TemplateField HeaderText="Photo">
<EditItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Bind("Photo") %>' />
<asp:FileUpload ID="FileUpload1" runat="server" />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblPhoto" runat="server" Text='<%# Bind("Photo") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="编辑">
<EditItemTemplate>
<asp:Button ID="btnUpdate" runat="server" Text="更新" CommandName="Update" />
<asp:Button ID="btnCancel" runat="server" Text="取消" CommandName="Cancel" />
</EditItemTemplate>
<ItemTemplate>
<asp:Button ID="btnEdit" runat="server" Text="编辑" CommandName="Edit"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
后端:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
private void BindData()
{
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(string));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Photo", typeof(string));
DataRow dr = dt.NewRow();
dr["ID"] = "1";
dr["Name"] = "张三";
dr["Photo"] = "D:\\a.jpg";
DataRow dr1 = dt.NewRow();
dr1["ID"] = "2";
dr1["Name"] = "李四";
dr1["Photo"] = "D:\\b.jpg";
dt.Rows.Add(dr);
dt.Rows.Add(dr1);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
BindData();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//更新数据的事在这里做
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
BindData();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && ((e.Row.RowState & DataControlRowState.Edit) > 0))
{
FileUpload fu = (FileUpload)e.Row.FindControl("FileUpload1");
Image image = (Image)e.Row.FindControl("Image1");
fu.Attributes.Add("onpropertychange", "javascript:document.getElementById('" + image.ClientID + "').src=document.getElementById('" + fu.ClientID + "').value");
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询