2

我是一个新的程序员,所以任何帮助或建议将不胜感激。

我有一个数据列表,其中包含一个显示一行数据的链接按钮。单击链接按钮时,应取消隐藏包含数据列表(也包含链接按钮)的面板,该面板显示更详细的信息。我遇到的问题是,当我单击摘要链接按钮时,它不会触发 javascript 来隐藏或显示详细信息面板。我没有得到任何异常,我的程序构建并运行,所以我不确定为什么 javascript 不会触发。仅供参考, DBClass 和 DbClass 对象是内部类,它们工作正常。这是我的代码:

using System;
usingSystem.Collections;
usingSystem.Configuration;
usingSystem.Data;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.HtmlControls;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Xml.Linq;
usingDBClass;


namespaceTimeLogging.pages
{
  publicpartialclassdbEntry:System.Web.UI.Page
  {
    QueryClassqc=newQueryClass();

  protectedvoidPage_Load(objectsender,EventArgse)
  {
    bindDlReportProjSum_devSummary();
  }

  //getsthelinkbuttonattributefortheemployeeidsothatitcanbeboundtothedatalist
protectedvoiddlReportProjSum_devSummary_OnItemDataBound(objectsender,DataListItemEventArgse)
{
  if(e.Item.ItemType == ListItemType.Item 
    || e.Item.ItemType == ListItemType.AlternatingItem)
  {
    DataListnestedDataList=(DataList)e.Item.FindControl("dlReportProjSum_devDetail");
    LinkButtonlinkbtn=(LinkButton)e.Item.FindControl("lbReportProjSum_devSummary");
    bindDlReportProjSum_devDetail(nestedDataList,linkbtn.Attributes["empid"]);
    //Panelpan=(Panel)e.Item.FindControl("panReportProjSum_devDetail");
  }
}

//hidesthedevedetailpanelonlinkbutttonclick
protectedvoiddlReportProjSum_devSummary_OnItemCommand(objectsender,DataListCommandEventArgse){

LinkButtonlb=(LinkButton)e.Item.FindControl("lbReportProjSum_devSummary");
Panelpan=(Panel)e.Item.FindControl("panReportProjSum_devDetail");
}

//thedatalistthatshowsasummaryofeachemployeewhohasworkedonaproject
protectedvoidbindDlReportProjSum_devSummary(){
DbClassdb=newDbClass();
DataTabledt=newDataTable();
stringsqlString=@"selectname,empid,sum(actualtime)astotal
fromTime_logging_vwProjDevDetail
whereprojid=1
groupbyempid,name";
db.OpenConnection();
db.Execute(sqlString);
dt=db.GetData.Table;
dlReportProjSum_devSummary.DataSource=dt;
dlReportProjSum_devSummary.DataBind();
db.CloseConnection();
db.Dispose();
}



//bindthenesteddatalistinthedevSummaryOnItemDataBoundevent
privatevoidbindDlReportProjSum_devDetail(DataListdl,stringdevEmpid)
{
DbClassdb=newDbClass();
DataTabledt=newDataTable();
stringsqlString=string.Format(@"selectDAYOF,ESTTIME,ACTUALTIME,NOTES,TASK
fromtime_logging_resourceswhere
projid=1andempid={0}",devEmpid);
db.OpenConnection();
db.Execute(sqlString);
dt=db.GetData.Table;
dl.DataSource=dt;
dl.DataBind();

db.CloseConnection();
db.Dispose();
}



////whenthedeveloperssummaryoftotalhoursonaprojectisclicked
protectedvoidlbReportProjSum_devSummary_Click(objectsender,EventArgse)
{
ClientScript.RegisterStartupScript(GetType(),"Javascript","HidePanel()",true);

}

}
}

ASPXpage////////////////////////////////////////////////////////////////////////////////


<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="dbEntry.aspx.cs"Inherits="TimeLogging.pages.dbEntry"%>

<%@RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="asp"%>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>UntitledPage</title>
<linkhref="../css/Main.css"rel="stylesheet"type="text/css"/>

<scripttype="text/javascript"language="javascript">
functionHidePanel()
{
alert("hello");
varpanel=document.getElementById('panReportProjSum_devDetail');
if(panel.style.display=='none')
{
panel.style.display='block';
}
else
{
panel.style.display='none';
}
}
</script>

</head>
<body>
<formid="form1"runat="server">

<asp:ToolkitScriptManagerID="ToolkitScriptManager1"runat="server">
</asp:ToolkitScriptManager>
<div>
<asp:PanelID="panMainReportsHolder"runat="server">

<asp:DataListID="dlReportProjSum_devSummary"runat="server"RepeatDirection="Vertical"
ShowFooter="False"ShowHeader="False"OnItemDataBound="dlReportProjSum_devSummary_OnItemDataBound"
OnItemCommand="dlReportProjSum_devSummary_OnItemCommand">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<div>
<asp:LinkButtonID="lbReportProjSum_devSummary"OnClick="lbReportProjSum_devSummary_Click"
runat="server"empid='<%#DataBinder.Eval(Container.DataItem,"empid")%>'name='<%#DataBinder.Eval(Container.DataItem,"name")%>'
total='<%#DataBinder.Eval(Container.DataItem,"total")%>'CssClass="developerSummaryLinkButton"><%#DataBinder.Eval(Container.DataItem,"name")%>'stotalhoursspentdevelopingtheproject:<%#DataBinder.Eval(Container.DataItem,"total")%>

</asp:LinkButton>

<asp:PanelID="panReportProjSum_devDetail"runat="server">

<asp:DataListID="dlReportProjSum_devDetail"runat="server"RepeatDirection="Vertical"
ShowFooter="False"ShowHeader="False">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<div>
<asp:LinkButtonID="LinkButton1"CssClass="developerDetailLinkButton"runat="server"
Enabled="false">Dateworked:<%#DataBinder.Eval(Container.DataItem,"dayof")%>task:<%#DataBinder.Eval(Container.DataItem,"task")%>numberofhoursworked:<%#DataBinder.Eval(Container.DataItem,"actualtime")%>anynotes:<%#DataBinder.Eval(Container.DataItem,"notes")%>
</asp:LinkButton>
</div>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:DataList>
</asp:Panel>


</div>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:DataList>
</asp:Panel>
</div>
</form>
</body>
</html>
4

1 回答 1

0

您需要连接您的 Linkbutton1 以触发 Javascript 事件。您可以使用 OnClientClick 属性执行此操作,如下所示:

<asp:LinkButtonID="LinkButton1"CssClass="developerDetailLinkButton"runat="server" Enabled="false" onclientclick="HidePanel();return false;"/>

Return False 阻止它调用 onclick 中设置的服务器端事件(如果有的话)。

阅读有关 onclient 的更多信息单击此处在此处输入链接描述

于 2012-10-26T13:51:16.033 回答