gpt4 book ai didi

c# - 使用 Linkbutton 和 C# 和 javascript 在数据列表中隐藏面板

转载 作者:太空宇宙 更新时间:2023-11-03 16:24:00 24 4
gpt4 key购买 nike

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

我有一个包含显示一行数据的链接按钮的数据列表。单击链接按钮时,应取消隐藏包含数据列表(也包含链接按钮)的面板,该面板显示更详细的信息。我遇到的问题是,当我单击摘要链接按钮时,它不会触发 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>

最佳答案

您需要连接 Linkbutton1 以触发 Javascript 事件。您可以像这样使用 OnClientClick 属性来执行此操作:

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

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

阅读更多关于 onclientclick here enter link description here

关于c# - 使用 Linkbutton 和 C# 和 javascript 在数据列表中隐藏面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13088104/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com