0

i am trying to bind my grid to table adapter data, this is what i do :

DataSourceDepartement dpt = new DataSourceDepartement();

DataSourceDepartementTableAdapters.departementTableAdapter
         adapter = new DataSourceDepartementTableAdapters.departementTableAdapter();
gridDepartement.DataSource = adapter.GetDataDepartement();
gridDepartement.DataBind();

aspx file :

<asp:GridView ID="gridDepartement" runat="server" CellPadding="4" ForeColor="Black" 
                    GridLines="Horizontal" AutoGenerateColumns="False" BackColor="White" 
                    BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" AllowSorting="true">
                    <Columns>
                        <asp:TemplateField ItemStyle-Width="20px">
                            <ItemTemplate>
                                <asp:CheckBox Id="cbSelect" runat="server"/>
                            </ItemTemplate>
                        </asp:TemplateField>          
                        <asp:CommandField ShowEditButton="True" ItemStyle-Width="20px" />
                        <asp:CommandField ShowDeleteButton="True" ItemStyle-Width="20px" />
                        <asp:TemplateField HeaderText="Departement Code">
                            <ItemTemplate>
                                <asp:label runat="server" ID="departementcode" ></asp:label>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
                    <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
                    <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
                </asp:GridView>

but somehow, my gridview does not show its data, what i miss?

4

1 回答 1

0

您需要使用该RowDataBound事件,访问该行的控件,GridView然后设置值:

所以发帖

还要确保没有抛出异常!

于 2013-04-30T13:05:48.043 回答