将不同的值传递给gridview超链接

时间:2013-08-17 10:57:54

标签: c# asp.net gridview

我正在asp.net页面上工作。我有一个objectdatasource和gridview。 gridview有两列。 objectdatasource返回一个包含5行的数据表。我希望当显示gridview的第5行时,用于创建超链接导航的ActionReportsShowTotalHF应该具有值1,否则它应该具有值0:

<asp:ObjectDataSource ID="ActionReportsODS" runat="server" TypeName="HRcomgeWebApp.Old_App_Code.DataLayer.HRActionLog" SelectMethod="GenerateReports">
                                    <SelectParameters>
                                        <asp:ControlParameter Name="dateFrom" Type="DateTime" ControlID="ActionReportsFromTextBox" PropertyName="Text" ConvertEmptyStringToNull="true" />
                                        <asp:ControlParameter Name="dateTo" Type="DateTime" ControlID="ActionReportsToTextBox" PropertyName="Text" ConvertEmptyStringToNull="true" />
                                        <asp:ControlParameter Name="companyId" Type="Int32" ControlID="ActionReportsCompaniesDDL" PropertyName="SelectedValue" ConvertEmptyStringToNull="true" />
                                        <asp:ControlParameter Name="registrantId" Type="Int32" ControlID="ActionReportsRegistrantIDHF" PropertyName="Value" ConvertEmptyStringToNull="true" />
                                        <asp:ControlParameter Name="vacancyId" Type="Int32" ControlID="ActionReportsVacancyIDHF" PropertyName="Value" ConvertEmptyStringToNull="true" />
                                    </SelectParameters>
                                </asp:ObjectDataSource>
                                <asp:GridView ID="gvActionReports" runat="server" SkinID="SmallListGridView" AutoGenerateColumns="False" EnableViewState="false" DataSourceID="ActionReportsODS">
                                    <Columns>
                                        <asp:BoundField DataField="Data" HeaderText="<%$ Resources:AdminStatistics, HeaderData %>"  />
                                        <asp:TemplateField HeaderText="<%$ Resources:AdminStatistics, HeaderCount %>" 
                                            ItemStyle-HorizontalAlign="Right" >
                                            <ItemTemplate>
                                                <asp:HyperLink ID="ShowDetailsHL" runat="server" Text='<%# Eval("Counts") %>' Visible='<%# Eval("Counts").ToString() != "0" %>'
                                                    NavigateUrl='<%# GetActionLogsDetailScript(Eval("Action").ToString()) %>' />

                                                <asp:Literal ID="CountLiteral" runat="server" Text='<%# Eval("Counts") %>' Visible='<%# Eval("Counts").ToString() == "0" %>' />
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                    </Columns>
                                </asp:GridView>

这是方法定义:

 protected string GetActionLogsDetailScript(string action)
        {
            return String.Format("JavaScript:OpenWindow('{0}?{1}={2}&{3}={4}&{5}={6}&{7}={8}&{9}={10}&{11}={12}&{13}={14}', 800, 600);",
                this.ResolveUrl(GlobalVariables.Page_ActionLogs),
                GlobalVariables.QueryString_Action,
                action,
                GlobalVariables.QueryString_DateFrom,
                ActionReportsFromTextBox.Text,
                GlobalVariables.QueryString_DateTo,
                ActionReportsToTextBox.Text,
                GlobalVariables.QueryString_CompanyID,
                ActionReportsCompaniesDDL.SelectedValue,
                GlobalVariables.QueryString_RegistrantID,
                ActionLogsRegistrantIDHF.Value,
                GlobalVariables.QueryString_VacancyID,
                ActionReportsVacancyIDHF.Value,
                GlobalVariables.QueryString_ShowTotal,
                ActionReportsShowTotalHF.Value
            );
        }

1 个答案:

答案 0 :(得分:0)

试试这个

display:none;

<asp:HyperLink ID="ShowDetailsHL" runat="server" Text='<%# Eval("Counts") %>'  <%# Eval("Counts").ToString() != "0" ? "" :"style='display:none;'"%> 
                                                    NavigateUrl='<%# GetActionLogsDetailScript(Eval("Action").ToString()) %>' />