本文介绍了如何从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">&lt;asp:GridView ID=&quot;GridView1&quot; runat=&quot;server&quot; AutoGenerateColumns=&quot;False&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;name&quot; /&gt;
           &lt;asp:BoundField DataField=&quot;score&quot; HeaderText=&quot;score&quot; /&gt;
           &lt;asp:BoundField DataField=&quot;address&quot; HeaderText=&quot;address&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;server&quot;  ToolTip= &lt;%#Eval(&quot;player_name&quot;) %&gt; AlternateText=&quot;image not found&quot; Height=&quot;100&quot; Width=&quot;100&quot; /&gt;
               &lt;/ItemTemplate&gt;
           &lt;/asp:TemplateField&gt;
           &lt;asp:CommandField ShowEditButton=&quot;true&quot; ShowCancelButton=&quot;true&quot; ShowDeleteButton=&quot;true&quot; ShowInsertButton=&quot;true&quot; ShowSelectButton=&quot;true&quot; /&gt;
       &lt;/Columns&gt;

   &lt;/asp:GridView&gt;</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事件中的绑定字段中检索值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 11:32