本文介绍了如何从row_updating事件中的绑定字段中检索值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的gridview是这样的,我正在使用命令字段
< pre lang = xml > & lt; asp:GridView ID =& quot ; GridView1&安培; QUOT; RUNAT =安培; QUOT;服务器&安培; QUOT;的AutoGenerateColumns =安培; QUOT假安培; QUOT; OnRowCancelingEdit =安培; QUOT; GridView1_RowCancelingEdit&安培; QUOT; OnRowDeleting =安培; QUOT; GridView1_RowDeleting&安培; QUOT; OnRowEditing =安培; QUOT; GridView1_RowEditing&安培; QUOT; OnRowUpdating =安培; QUOT; GridView1_RowUpdating&安培; QUOT; & gt;
& lt; Columns& gt;
& lt; asp:BoundField DataField =& quot; player_name& quot;的HeaderText =安培; QUOT;名称&安培; QUOT; /&安培; GT;
& lt; asp:BoundField DataField =& quot;得分& quot;的HeaderText =安培; QUOT;得分&安培; QUOT; /&安培; GT;
& lt; asp:BoundField DataField =& quot; address& quot;的HeaderText =安培; QUOT;地址&安培; QUOT; /&安培; GT;
& lt; asp:TemplateField HeaderText =& quot; photo& quot;& gt;
& lt; ItemTemplate& gt;
& lt; asp:Image ImageUrl =& lt;%#Eval(& quot; photo& quot;)%& gt; RUNAT =安培; QUOT;服务器&安培; QUOT; ToolTip =& lt;%#Eval(& quot; player_name& quot;)%& gt; AlternateText =& quot; image not found& quot;高度=安培; QUOT; 100&安培; QUOT;宽度=安培; QUOT; 100&安培; QUOT; /&安培; GT;
& lt; / ItemTemplate& gt;
& lt; / asp:TemplateField& gt;
& lt; asp:CommandField ShowEditButton =& quot; true& quot; ShowCancelButton =安培; QUOT;真&安培; QUOT;的ShowDeleteButton =安培; QUOT;真&安培; QUOT; ShowInsertButton =安培; QUOT;真&安培; QUOT; ShowSelectButton =安培; QUOT;真&安培; QUOT; /&安培; GT;
& lt; / Columns& gt;
& lt; / asp:GridView& gt; < / pre >
和代码隐藏我正在尝试的是
< pre lang = cs > 受保护void GridView1_RowUpdating(object sender,GridViewUpdateEventArgs e)
{
string name =(GridView1.Rows [e.RowIndex] .Cells [0])。Text;
int score = Convert.ToInt32(GridView1.Rows [e.RowIndex] .Cells [1] .Text);
string adress = GridView1.Rows [e.RowIndex] .Cells [2] .Text;
updateTheRow(姓名,得分,地址);
} < / pre >
其中updateTheRow是我更新数据库记录的方法。
解决方案
my gridview is like this and i am using command field <pre lang="xml"><asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" > <Columns> <asp:BoundField DataField="player_name" HeaderText="name" /> <asp:BoundField DataField="score" HeaderText="score" /> <asp:BoundField DataField="address" HeaderText="address" /> <asp:TemplateField HeaderText="photo"> <ItemTemplate> <asp:Image ImageUrl= <%#Eval("photo") %> runat="server" ToolTip= <%#Eval("player_name") %> AlternateText="image not found" Height="100" Width="100" /> </ItemTemplate> </asp:TemplateField> <asp:CommandField ShowEditButton="true" ShowCancelButton="true" ShowDeleteButton="true" ShowInsertButton="true" ShowSelectButton="true" /> </Columns> </asp:GridView></pre> and in codebehind what i am trying is <pre lang="cs">protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { string name = (GridView1.Rows[e.RowIndex].Cells[0]).Text; int score = Convert.ToInt32(GridView1.Rows[e.RowIndex].Cells[1].Text); string adress = GridView1.Rows[e.RowIndex].Cells[2].Text; updateTheRow(name, score, adress); }</pre> where updateTheRow is my method to update the record in database.
解决方案
这篇关于如何从row_updating事件中的绑定字段中检索值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!