【问题标题】:Binding Itemtemplate of GridView with DataTableGridView的Itemtemplate与DataTable的绑定
【发布时间】:2012-07-23 11:24:05
【问题描述】:

我在 .aspx 文件中有下面的 GridView。

 <asp:GridView ID="grdScopeList" runat="server">
    <Columns>
    <asp:TemplateField>
    <ItemTemplate>
    <asp:CheckBox ID="ScopeChk" runat="server" Checked=false />
    </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="sync_scope_name"  Visible=true />
    </Columns>
    </asp:GridView>

我正在使用 Dataset/DataTable 来分配 GridView。下面是 PageLoad 事件中使用的代码 sn-p。

string scopecomm="select sync_scope_name from Sync.scope_info";
DataSet ds_scope = new DataSet();
ds_scope = GetData(scopecomm, remoteconn);   grdScopeList.DataSource = ds_scope;
grdScopeList.DataBind();

但是我得到了列sync_scope_name 两次。我能够将Dataset 中的列sync_scope_name 绑定到BoundField。我只需要显示它一次

问候,

萨钦K

【问题讨论】:

  • 您确定 GetData 没有两次获取列 sync_scope_name
  • Getdata 只获得单列,即sync_scope_name。

标签: asp.net gridview


【解决方案1】:

您的查询很可能返回重复项。

对您的数据库手动运行查询以丢弃它。

如果查询应该返回重复项并且您只想显示一次,则需要对查询进行分组

select sync_scope_name 
from Sync.scope_info
group by sync_scope_name 

或者使用distinct关键字

select distinct sync_scope_name from Sync.scope_info

【讨论】:

    【解决方案2】:

    我在 GridView 中添加了 AutoGenerateColumns="false"。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-27
      • 1970-01-01
      • 1970-01-01
      • 2017-06-14
      • 1970-01-01
      • 2010-10-30
      • 2014-12-22
      相关资源
      最近更新 更多