如何在数据绑定后显示网格视图

时间:2014-05-14 05:10:29

标签: c# asp.net gridview

我正在使用GridView绑定数据库中的数据。当我执行程序时,数据将绑定在'Gridview'中,但Grid未显示。但是当我得到网格行Count时,它显示3.为什么它不显示。我在Search之前和之后使用同一网格作为商店值。在搜索之前(加载时)所有值都将是Bind,但是在Gird中没有变化之后......

代码:

 gvUserManage.DataSource = dsCandiDeat.Tables[0];
   gvUserManage.PageIndex = PageIndex;
   gvUserManage.DataBind();
   int c= gvUserManage.Rows.Count;

设计

<asp:GridView ID="gvUserManage" runat="server" Style="border: 1px;" RowStyle-BorderColor="#ebf3e4" 
                                RowStyle-BorderStyle="None" GridLines="Both" PageSize="10" 
                                AllowPaging="true" AutoGenerateColumns="false"
                                Width="100%" AlternatingRowStyle-BackColor="" 
                                CssClass="grdCandList" RowStyle-CssClass="RowStyle"
                                AlternatingRowStyle-CssClass="AltRowStyle" 
                                HeaderStyle-CssClass="grdheaderCandList" DataKeyNames="UserId" 
                                onrowcommand="gvUserManage_RowCommand" 
                                onrowdatabound="gvUserManage_RowDataBound" 
                                onpageindexchanging="gvUserManage_PageIndexChanging" AllowSorting="true" 
                                onsorting="gvUserManage_Sorting">
                                <EmptyDataTemplate>
                                    <div class="shadowbox" style="min-height: 75px;">
                                        <br />
                                        <center>No Data Found.</center>
                                    </div>
                                </EmptyDataTemplate>
                                <Columns>
                                    <asp:TemplateField HeaderText="Name" ItemStyle-CssClass="grdcolumncenter" HeaderStyle-CssClass="grdcolumnheadermiddle pad_left5 pad_right5 NameHeaderWidth" SortExpression="CandiName">
                                        <ItemTemplate>
                                            <h4 style="font-size:13px; text-align:left; font-weight:normal !important; color:rgb(67, 73, 75); font-family:Calibri;"><asp:LinkButton ID="lnkCandidateView" runat="server" style="text-decoration:none; color:#1382ce;" onmouseover='mouseover(this);' onmouseout='mouseout(this);' CommandName="View" CommandArgument='<%# Eval("CandidateId")%>' ><asp:Label ToolTip='<%# Eval("CandiName")%>' ID="lblGrdCandiName" runat="server" Text='<%# Eval("CandiName")%>'></asp:Label></asp:LinkButton></h4>
                                            <div style="float: left;">
                                                <asp:UpdatePanel ID="UpdatePanel5" runat="server" UpdateMode="Conditional">
                                                    <ContentTemplate>
                                                        <asp:ImageButton ID="imgbtnNewCmnt" runat="server" Visible="false" CommandName="NewCmnt"
                                                            CommandArgument='<%# Eval("CandidateId")%>' ToolTip="New Comment" ImageUrl="~/Images/reminder.png" />
                                                    </ContentTemplate>
                                                </asp:UpdatePanel>
                                            </div>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Position" HeaderStyle-HorizontalAlign="Left" HeaderStyle-CssClass="grdcolumnheadermiddle pad_left5 pad_right5 PositionHeaderWidth" SortExpression="CurrPosi">
                                        <ItemTemplate>
                                            <asp:Label ID="lblGrdPosition" runat="server" Text='<%# Eval("CurrPosi")%>' ToolTip='<%# Eval("CurrPosi")%>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Experience" HeaderStyle-HorizontalAlign="Left" HeaderStyle-CssClass="grdcolumnheadermiddle pad_left5 pad_right5 ExperienceHeaderWidth">
                                        <ItemTemplate>
                                            <asp:Label ID="lblGrdExperience" runat="server" Text='<%# Eval("TotWrkExp")%>' ToolTip='<%# Eval("TotWrkExp")%>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Technology" ItemStyle-HorizontalAlign="left" HeaderStyle-CssClass="grdcolumnheadermiddle pad_left5 pad_right5 TechnologyHeaderWidth">
                                        <ItemTemplate>
                                            <asp:Label ID="lblGrdTechnology" runat="server" Text='<%# Eval("SkillSet")%>' ToolTip='<%# Eval("SkillSet")%>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Status" ItemStyle-HorizontalAlign="left" HeaderStyle-CssClass="grdcolumnheadermiddle pad_left5 pad_right5 StatusHeaderWidth" SortExpression="USStatus">
                                        <ItemTemplate>
                                            <asp:Label ID="lblGrdStatus" runat="server" Text='<%# Eval("USStatus")%>' ToolTip='<%# Eval("USStatus")%>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Location" ItemStyle-HorizontalAlign="left" HeaderStyle-CssClass="grdcolumnheadermiddle pad_left5 pad_right5 LocationHeaderWidth" SortExpression="Location">
                                        <ItemTemplate>
                                            <asp:Label ID="lblGrdLocation" runat="server" Text='<%# Eval("Location")+"  "+ Eval("JobZipCode")%>' ToolTip='<%# Eval("Location")+"  "+ Eval("JobZipCode")%>' AccessKey                            ></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Block Resume" ItemStyle-HorizontalAlign="left" HeaderStyle-CssClass="grdcolumnheadermiddle pad_left5 pad_right5 SalHeaderWidth">
                                        <ItemTemplate>
                                            <asp:CheckBox ID="chkResume" runat="server" checked='<%# Eval("ActiveResume").ToString().Equals("n")%>'/>
                                        </ItemTemplate>
                                    </asp:TemplateField>
</Columns>
                                <PagerStyle CssClass="pgr" />
                                <pagersettings mode="NumericFirstLast" firstpagetext="First" lastpagetext="Last" pagebuttoncount="5" position="Bottom"/> 
                                <HeaderStyle CssClass="grdheaderCandList" />
                            </asp:GridView>

先谢谢

1 个答案:

答案 0 :(得分:0)

How to: Set Access Keys for Web Server Control

您的代码:

<asp:Label ID="lblGrdLocation" runat="server" 
           Text='<%# Eval("Location")+"  "+ Eval("JobZipCode")%>' 
           ToolTip='<%# Eval("Location")+"  "+ Eval("JobZipCode")%>' AccessKey >   
</asp:Label>

可能它没有解决问题但是这个陈述在您的标记中可能会有问题。

要为Label控件指定Access Key,您必须指定AssociatedControlID。有关详细信息,请参阅上面的MSDN参考。

此外,您必须查看gvUserManage_RowDataBound事件。