gridview与列表数据源绑定

时间:2014-04-22 17:05:56

标签: asp.net

我有一个问题,我从列表中检索数据,我想将数据绑定到网格视图

设计

 <asp:GridView ID="GridView1" runat="server"  AutoGenerateColumns="False" 
                            class="gridview" onrowcommand="GridView1_RowCommand" 
                            ShowHeader="False">
                            <Columns>                                                                 
                                <asp:TemplateField>    
                                    <ItemTemplate>          

                                        <div style="width:200px; float:left;"><asp:LinkButton class="linkbutton" ID="LinkButton1" runat="server" Text="<%# bind('group_name') %>" CommandName="<%# bind('group_name') %> "></asp:LinkButton></div>                        
                                    </ItemTemplate>    
                                </asp:TemplateField>
                            </Columns>        
                        </asp:GridView>  

背后的代码

 List<NewsGroup> group_list = DataQueried.ReadNewsGroupsFromDB(GlobalData.RegUser.getUserRegId());
    using (connection3)
                    {
                        using (SqlCommand cmdd = new SqlCommand())
                        {                       
                            cmdd.Connection = connection3;
                            connection3.Open();
                            GridView1.DataSource = group_list;
                            GridView1.DataBind();                        
                            connection3.Close();
                        }
                    }

错误是:

Exception Details: System.Web.HttpException: DataBinding: 'MyNews.NewsGroup' does not contain a property with the name 'group_name'.

0 个答案:

没有答案