我有3个标签,我想在其中显示相应的数据。我已将onserverclick
的属性赋予<li>
内的锚标记。但问题是它没有开火。
此外,当我尝试断点时,它无法正常工作。这是我的html代码: -
<ul class='tabs1'>
<li><a href='#tab1' id="allNews" runat="server" onserverclick="allNews_ServerClick">All News</a></li>
<li><a href='#tab2' id="forNgo" runat="server" onserverclick="forNgo_ServerClick">For NGO</a></li>
<li><a href='#tab3' id="fromNgo" runat="server" onserverclick="fromNgo_ServerClick">From NGO</a></li>
</ul>
请提出可能妨碍工作的问题。
更新
服务器代码: -
protected void fromNgo_ServerClick(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DefaultCSRConnection"].ConnectionString))
{
string query = "SSELECT dbo.tbl_post.title, dbo.tbl_post.description, dbo.tbl_post.active, dbo.tbl_post.dateforPost, dbo.tbl_ngoname.ngo_name, dbo.tbl_User.usertype FROM dbo.tbl_post INNER JOIN dbo.tbl_User ON dbo.tbl_post.UserId = dbo.tbl_User.Id INNER JOIN dbo.tbl_ngoname ON dbo.tbl_post.NgoId = dbo.tbl_ngoname.Id AND dbo.tbl_User.NgoId = dbo.tbl_ngoname.Id WHERE (dbo.tbl_User.usertype=2)";
SqlDataAdapter sda = new SqlDataAdapter(query, conn);
DataTable dt = new DataTable();
sda.Fill(dt);
lstNews.DataSource = dt;
lstNews.DataBind();
}
}
答案 0 :(得分:0)
protected void Tab1Function()
{
using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DefaultCSRConnection"].ConnectionString))
{
string query = "SELECT dbo.tbl_post.title, dbo.tbl_post.description, dbo.tbl_post.active, dbo.tbl_post.dateforPost, dbo.tbl_ngoname.ngo_name, dbo.tbl_User.usertype FROM dbo.tbl_post INNER JOIN dbo.tbl_User ON dbo.tbl_post.UserId = dbo.tbl_User.Id INNER JOIN dbo.tbl_ngoname ON dbo.tbl_post.NgoId = dbo.tbl_ngoname.Id AND dbo.tbl_User.NgoId = dbo.tbl_ngoname.Id WHERE (dbo.tbl_User.usertype=2)";
SqlDataAdapter sda = new SqlDataAdapter(query, conn);
DataTable dt = new DataTable();
sda.Fill(dt);
lstNews.DataSource = dt;
lstNews.DataBind();
}
}
然后,在你的PageLoad
中使用它 If (!IsPostBack)
{
Tab1Function();
}
类似的东西。
编辑:我认为您的标签无效。因此,让我们直接指向TabContainer。<ajaxToolkit:TabContainer ID="Tab_Container" runat="server" ActiveTabIndex="0" CssClass="CustomTabStyle" EnableTheming="False" ScrollBars="Both" Style="vertical-align: top" Width="900px">
<ajaxToolkit:TabPanel ID="TabPanel_1" runat="server" HeaderText="TabPanel1" ScrollBars="Both">
<HeaderTemplate> All News </HeaderTemplate>
<ContentTemplate>
//Your Table/Datagrid containing your data here.. Whatever you are binding your data to.
<table><tr><td></td></tr></table>
</ContentTemplate>
</ajaxToolkit:TabPanel>
<ajaxToolkit:TabPanel ID="TabPanel_2" runat="server" HeaderText="TabPanel3">
<HeaderTemplate>
For NGO
</HeaderTemplate>
<ContentTemplate>
<table><tr><td></td></tr></table>
</ContentTemplate></ajaxToolkit:TabPanel></ajaxToolkit:TabContainer>
我希望这是有道理的。
答案 1 :(得分:0)
您需要在页面加载中为Anchor标记创建Click事件,如下所示
private void Page_Load(object sender, System.EventArgs e)
{
HtmlAnchor HA = new HtmlAnchor();
HA.ServerClick += new EventHandler(linkclickeve1);
HtmlAnchor HA2 = new HtmlAnchor();
HA2.ServerClick += new EventHandler(linkclickeve2);
}
protected void linkclickeve1(object sender, System.EventArgs e)
{
}
protected void linkclickeve2(object sender, System.EventArgs e)
{
}