2014-09-19 105 views
1

我想在DOTNETNUKE模塊中使用SQL dataadapter填充gridview。我的問題是,當我這樣做時,我得到一個「重複」表。對我來說任何見解?如何擺脫Asp.Net中的重複gridview?

這背後

 SqlCommand command   = new SqlCommand(); 
     SqlDataAdapter adapter  = new SqlDataAdapter(); 
     DataSet ds     = new DataSet();   
     SqlConnection connection = new SqlConnection(connString); 

     connection.Open(); 
     command.Connection = connection; 
     command.CommandType = CommandType.StoredProcedure; 
     command.CommandText = "PopulateGridView"; 
     adapter    = new SqlDataAdapter(command); 
     adapter.Fill(ds); 
     connection.Close(); 

     gvStatusUpdate.DataSource = ds.Tables[0]; 
     gvStatusUpdate.DataBind(); 

我的代碼這是爲GridView我的前端處的代碼。

<asp:GridView ID="gvStatusUpdate" runat="server"> 
<Columns> 
     <asp:BoundField ReadOnly="True" HeaderText="ID" DataField="ID"></asp:BoundField> 
     <asp:BoundField HeaderText="ReportedDate" DataField="ReportedDate"></asp:BoundField> 
     <asp:BoundField HeaderText="CurrentStatus" DataField="CurrentStatus"></asp:BoundField> 
     <asp:BoundField HeaderText="ResolvedDate" DataField="ResolvedDate"></asp:BoundField> 
     <asp:BoundField HeaderText="Issue" DataField="Issue"></asp:BoundField> 
</Columns> 
</asp:GridView> 

回答

1

AutoGenerateColumns="False"添加到您的GridView。

<asp:GridView ID="gvStatusUpdate" AutoGenerateColumns="False" runat="server"> 

MSDN

+0

這是一個極好的答案。簡短而精確。 – MarsOne 2014-09-19 07:51:34