本文介绍了从GridView的从code得到评估和演示背后的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个GridView,从具有几个模板列的数据库负载。我如何检索code后面的评估和演示价值?换句话说,我所需要的模板字段名称该列。

我想获得注册,并将其存储在一个变量。

 < ASP:的TemplateField的HeaderText =REGSORTEX pression =注册>
     <&EditItemTemplate的GT;
            < ASP:复选框ID =cbRegEdit=服务器选中='<%#(INT)的eval(注册)== 1%GT;' />
     < / EditItemTemplate中>
     <&ItemTemplate中GT;
                < ASP:复选框ID =cbReg=服务器启用=false的选中='<%#(INT)的eval(注册)== 1%GT;'>
                 < / ASP:复选框>
      < / ItemTemplate中>
      < ItemStyle Horizo​​ntalAlign =中心/>
< / ASP:的TemplateField>


解决方案

您必须勾 OnRowDataBound 键,这样做:

 保护无效GridView1_RowDataBound(对象发件人,GridViewRowEventArgs E)
{  如果(e.Row.RowType == DataControlRowType.DataRow)
  {
    VAR注册=((YourType)e.Row.DataItem).Registrations;
    //做一点事
  }
}

您的GridView将不得不为:

 < ASP:GridView的OnRowDataBound =GridView1_RowDataBound...

I have a gridview that loads from a database that has several TemplateFields. How do I retrieve the Eval value from code behind? In other words I need the template field name for that column.

I want to get "Registrations" and store it in a variable.

<asp:TemplateField HeaderText="REG" SortExpression="Registrations">
     <EditItemTemplate>
            <asp:CheckBox ID="cbRegEdit" runat="server" Checked='<%# (int)Eval("Registrations") == 1 %>' />
     </EditItemTemplate>
     <ItemTemplate>
                <asp:CheckBox ID="cbReg" runat="server" Enabled="false" Checked='<%# (int)Eval("Registrations") == 1 %>'>
                 </asp:CheckBox>
      </ItemTemplate>
      <ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
解决方案

You have to hook to OnRowDataBound and do something like:

protected void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
{

  if(e.Row.RowType == DataControlRowType.DataRow)
  {
    var registrations = ((YourType)e.Row.DataItem).Registrations;
    //do something 
  }
}

Your GridView would then have to be:

<asp:GridView OnRowDataBound="GridView1_RowDataBound" ...

这篇关于从GridView的从code得到评估和演示背后的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 11:58