如何从外部更新按钮更新Gridview的行 [英] How Do I Update A Gridview's Row From An External Update Button

查看:144
本文介绍了如何从外部更新按钮更新Gridview的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我是asp.net的新手,所以请光临我



到目前为止我有一个绑定到xml数据源的网格视图,当用户点击编辑它将打开一个新视图的任何行,此视图包含3个文本框。每个文本框都填充了所选行的数据。



我的问题是如何通过克服此视图中的更新按钮来更新gridview行的值



aspx文件中的视图:



< asp:查看ID =编辑runat =server>



< td>

< asp:TextBox ID =editnamerunat =server>
id < asp:TextBox ID =editidrunat =server>

name
info

< asp:TextBox ID =editinfo runat =server>


< asp:Button Text =updateID =updaterunat =serverOnClick = update_Click/>









将其与gridview当用户点击编辑时。





代码隐藏文件:



protected void gv1_RowCommand(object sender,GridViewCommandEventArgs e)

{

if(e.CommandName ==eddit)

{

//用于编辑和更新的视图2



MultiView1.ActiveViewIndex = 2;

GridViewRow row =( GridViewRow)((Control)e.CommandSource).Parent.Parent;

//将我的文本框链接到gridview中的标签

editid.Text =(row.FindControl (labelid)为标签)。文字;

editname.Text =(row.FindControl(labelname)as Label).Text;

editinfo.Text =(row.FindControl(labelinfo)as Label).Text;





}

}





如何将我在文本框中键入的值保存到gridview的选定行或将其保存到xml文件?



protected void update_Click(object sender,EventArgs e)

{

//我想在这里添加一些代码来更新文本框到选定行的值。这是可能的

}





我很抱歉这个愚蠢的问题但是我我很茫然。



非常感谢你的帮助,请和我一起开始我是这里的初学者

解决方案

为此,您必须在 RowCommand 中取一些内容,这是一些唯一的 ID 或者其他的东西。在 View 中,将其存储在 HiddenField 中。



内部更新按钮单击事件,获取 ID 值,并通过使用 ID

hello, i'm new to asp.net so please bare with me

so far i have a grid view bound to an xml data source, when the user clicks on edit on whatever row it will open up a new view, this view holds 3 text boxes. Each textbox is populated with the selected row's data.

my question is how can i update the value of the gridview's row by clinking on the "update" button located in this view

the view in the aspx file :

<asp:View ID="edit" runat="server" >

id <asp:TextBox ID="editid" runat="server" >
name
<asp:TextBox ID="editname" runat="server" >
info
<asp:TextBox ID="editinfo" runat="server" >

<asp:Button Text="update" ID="update" runat="server" OnClick="update_Click" />




linked it with the gridview when the user clicks on edit.


code behind file :

protected void gv1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "eddit")
{
//view 2 used for editing and updating

MultiView1.ActiveViewIndex = 2;
GridViewRow row = (GridViewRow)((Control)e.CommandSource).Parent.Parent;
//linked my textboxes to the labels in the gridview
editid.Text = (row.FindControl("labelid") as Label).Text;
editname.Text = (row.FindControl("labelname") as Label).Text;
editinfo.Text = (row.FindControl("labelinfo") as Label).Text;


}
}


how do i save the values i typed in the text boxes to the gridview's selected row or save it to the xml file?

protected void update_Click(object sender, EventArgs e)
{
// i want to add some code here to update the values from the textbox to the selected row. is this possible
}


i'm sorry for the stupid question but i am at a loss.

thank you very much for your help, and please bare with me i am a beginner in this

解决方案

For this, you have to take something inside RowCommand, which is unique like some ID or something. Inside the View, store it in a HiddenField.

Inside Update Button Click Event, get the ID value and update that particular row in XML by searching with the ID.


这篇关于如何从外部更新按钮更新Gridview的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆