私は新しいプログラマーなので、助けや提案をいただければ幸いです。
データの行を表示するリンクボタンを含むデータリストがあります。リンクボタンをクリックすると、より詳細な情報を表示するデータリスト(リンクボタンも含む)を含むパネルが再表示されます。私が抱えている問題は、概要リンクボタンをクリックしても、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>