gridview.databind()没有刷新

时间:2014-06-27 11:17:24

标签: c# asp.net gridview data-binding

我有一个gridview:

                                                         

                            <asp:TemplateField>
                                <HeaderTemplate>
                                    <asp:Label ID="lblHeaderDesc" runat="server" CssClass="Highlights_header" Text="Description"> </asp:Label>
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblDesc" runat="server" CssClass="Reportlabel" Text='<%# Bind("ProgDesc") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField>
                                <HeaderTemplate>
                                    <asp:Label ID="lblHeaderStartDate" runat="server" CssClass="Highlights_header" Text="Start Date"> </asp:Label>
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblStartDate" runat="server" CssClass="Reportlabel" Text='<%# Bind("StartDate") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField>
                                <HeaderTemplate>
                                    <asp:Label ID="lblHeaderEndDate" runat="server" CssClass="Highlights_header" Text="End Date"> </asp:Label>
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblEndDate" runat="server" CssClass="Reportlabel" Text='<%# Bind("EndDate") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField ItemStyle-CssClass="GridRow_Amount">
                                <HeaderTemplate>
                                    <asp:Label ID="lblHeaderBudget" runat="server" CssClass="Highlights_header" Text="Budget Amount"> </asp:Label>
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblBudget" runat="server" CssClass="Reportlabel" Text='<%# Bind("Budget") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField>
                                <HeaderTemplate>
                                    <asp:Label ID="lblHeaderStatus" runat="server" CssClass="Highlights_header" Text="Status"> </asp:Label>
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblStatus" runat="server" CssClass="Reportlabel" Text='<%# Bind("Status") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField ItemStyle-CssClass="GridRow_Links">
                                <HeaderTemplate>
                                    <asp:Label ID="lblHeaderView" runat="server" CssClass="Highlights_header" Text="View Details"> </asp:Label>
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:LinkButton ID="lnkProgName" runat="server" CssClass="Reportlabel" Text="Open"
                                        OnClick="lnkProgName_Click"></asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                        <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
                        <RowStyle HorizontalAlign="Left" CssClass="GridRow_DSM" />
                        <HeaderStyle HorizontalAlign="Center" CssClass="GridHeaderRow" />
                        <AlternatingRowStyle HorizontalAlign="Left" CssClass="GridRowAlt_DSM" />
                    </asp:GridView>

在我正在使用的代码中

grvProgramSearch.datasource = somedatasource //这是填充的 grvProgramSearch.databind()

但是,数据源已正确填充,但gridview未填充。

1 个答案:

答案 0 :(得分:0)

grvProgramSearch.DataBind();

后,

grvProgramSearch.DataSource = somedatasource;