[已解决问题] gridview rowcommand下通过绑定[列名]取值
提问时间: 2008-03-24 10:36
悬赏分:5 浏览:670 次

 <asp:GridView ID="gvOrderSetWithEscrow" runat="server" 
                      <Columns>
                <asp:boundfield DataField="UserName" HeaderText="用户名" ReadOnly="True">
                </asp:boundfield>
  <asp:templateField HeaderText="操作" >
                    <ItemTemplate>
                        <asp:Button ID="btnPayAmount" runat="server" Text="确定" CommandName="Ok" />
                    </ItemTemplate>
               </asp:TemplateField>
            </Columns>
        </asp:GridView>

---------------------------
  protected void gvOrderSetWithEscrow_RowCommand(object sender, GridViewCommandEventArgs e)
        {                   
            if (e.CommandName == "Ok")
            {  Control cmdControl = e.CommandSource as Control;  
                GridViewRow row = cmdControl.NamingContainer as GridViewRow;
                int rowindex = row.RowIndex;
                if (row.RowType == DataControlRowType.DataRow)
                {  string username = gvOrderSetWithEscrow.Rows[rowindex].Cells[0].Text.ToString();//这里,我不想通过 0 来取值,而是通过绑定的列名[username]来取值,应该怎么取


问题补充:如果存在多列的话,我还要数清楚1,2,3,4等等,那很麻烦,我想通过列名来获取值,这样会更好一点,无论html中怎么变化,.cs中就不用更改了

最佳答案
我一般使用Repeater加上一个按钮,再添加它的 CommandArgument 来完成这种工作. Repeater无论是性能还是灵活性上比GW都要好些.~~~
2008/3/24 11:43:48 回答者:沙加


提问者对于答案的评价:我用headertext去取值,因为它的值是固定不变的
其它回答(1)
GW里也可以指定CommandArgument 来完成这个工作,或者用datakeysname与CommandArgument 结合起来都可以完成这个工作
5个月前   回答者:AndyFish - 小虾三级
评论
   您需要登录以后才能回答!
 

我要提问

我的问题


快到期问题

> 问题排行榜

相关链接