有的时候想取不是编辑状态的值,这个时候通常会使用模板列中放置TextBox通过e.Item.FindControl取值,有的网友问为什么取不到?这要看你前台的列怎么写的了,下面分别写出四种情况和这四种情况下面的取值方式:

 1如何取得DataGrid绑定列和模板列中的值<asp:DataGrid id="DataGrid1" runat="server" AutoGenerateColumns="False" AllowPaging="True"> 
 2如何取得DataGrid绑定列和模板列中的值                <Columns> 
 3如何取得DataGrid绑定列和模板列中的值                    <asp:BoundColumn DataField="vName" HeaderText="姓名0"></asp:BoundColumn> 
 4如何取得DataGrid绑定列和模板列中的值                    <asp:TemplateColumn HeaderText="姓名1"> 
 5如何取得DataGrid绑定列和模板列中的值                        <ItemTemplate> 
 6如何取得DataGrid绑定列和模板列中的值                            姓名 
 7如何取得DataGrid绑定列和模板列中的值                        </ItemTemplate> 
 8如何取得DataGrid绑定列和模板列中的值                    </asp:TemplateColumn> 
 9如何取得DataGrid绑定列和模板列中的值                    <asp:TemplateColumn HeaderText="姓名2"> 
10如何取得DataGrid绑定列和模板列中的值                        <ItemTemplate> 
11 

列出了4种大家可能遇到的列:
(1)绑定列
(2)模板列中直接放静态的字符串
(3)模板列中直接放绑定的字符串
(4)模板列中通过Label放绑定的字符串

下面说明在按下了删除按钮以后的四种取值的方式:

1如何取得DataGrid绑定列和模板列中的值if(e.CommandName=="del"
2 

(1)第一种用绑定列的方式可以直接通过Cells[i].Text取
(2)第二种方式也直接可以取,但是讨厌的vs.net总是会在前台把列中的内容换行,所以这里还需要对输出的东西进行去除首尾的空格
(3)第三种方式不能直接通过Cells[i].Text取到值,可以通过上面给出的方法来取,同样需要去除首尾的空格
(4)第四种方式也是最简单的方式,当然你可以直接写e.Item.FindControl("name")

相关文章:

  • 2022-12-23
  • 2021-09-30
  • 2022-12-23
  • 2022-01-06
  • 2022-02-11
  • 2021-09-14
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-13
  • 2021-11-26
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案