如何将手风琴与中继器绑定 [英] how to bind accordion with repeater
本文介绍了如何将手风琴与中继器绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友们
我试图在运行时绑定手风琴控件。标头正在加载,但内容未加载。请纠正我错误的地方
这是加载手风琴的代码Header
Hi, Friends
I am trying to bind accordion control at run time. Header is loading,but the content is not loading. please correct me where i gone wrong
This is the code to load accordion Header
public DataTable EventName()
{
string tablename = "Event";
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select EventName from EventNames order by EventName";
return GetData(cmd, tablename).Tables[0];
}
在页面加载事件中我写这样的
In the page load event i write like this
if (!IsPostBack)
{
dataacess da = new dataacess();
DataTable dt = da.EventName();
Accordion1.DataSource = dt.DefaultView;
Accordion1.DataBind();
}
aspx页面设计是这样的
the aspx page design is like this
<asp:Accordion runat="server" ID="Accordion1" SuppressHeaderPostbacks="true" HeaderCssClass="accordionHeader"
HeaderSelectedCssClass="accordionHeaderSelected" ContentCssClass="accordionContent" Width="500"
OnItemDataBound="Accordion1_ItemDataBound">
<HeaderTemplate>
<asp:Label runat="server" ID="lblEventName" Text='<%#Eval("EventName") %>'> </asp:Label>
</HeaderTemplate>
<ContentTemplate>
<asp:HiddenField runat="server" ID="hidEventName" Value='<%#Eval("EventName") %>'>
</asp:HiddenField>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<p>
<asp:Label runat="server" ID="litDate" Text='<%# DataBinder.Eval(Container.DataItem, "Description") %>'
Font-Size="Medium" ForeColor="Maroon" Font-Bold="True"></asp:Label><br />
<asp:Literal runat="server" ID="litDesc1" Text='<%# "Date: " + DataBinder.Eval(Container.DataItem, "EDate", "{0:dd/MMM/yyyy,dddd}") %>'></asp:Literal>
<br />
Description:
<asp:Literal runat="server" ID="litDesc2" Text='<%# DataBinder.Eval(Container.DataItem, "Description2") %>'></asp:Literal></p>
</ItemTemplate>
<SeparatorTemplate>
<hr />
</SeparatorTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:Accordion>
Accordion OnItemDataBound事件
Accordion OnItemDataBound event
protected void Accordion1_ItemDataBound(object sender, AjaxControlToolkit.AccordionItemEventArgs e)
{
if (e.ItemType==AjaxControlToolkit.AccordionItemType.Content)
{
Repeater Repeater1 = (Repeater)e.AccordionItem.FindControl("Repeater1");
HiddenField hidEventName = (HiddenField)e.AccordionItem.FindControl("hidEventName");
dataacess da = new dataacess();
Repeater1.DataSource = da.EventHistory(pname, hidEventName.ToString());
Repeater1.DataBind();
}
}
如果我单独使用代码绑定转发器,它的工作没有任何问题。
我应该在哪里进行更改才能正常工作
If i use the code separately to bind the repeater its working without any problem.
Where i should i make changes to work it proper
推荐答案
我在调试时发现错误并找到了溶剂。
i已更改.ToString()到.Value
I find my mistake while debugging and found the sollution.
i changed .ToString() to .Value
Repeater1.DataSource = da.EventHistory(pname, hidEventName.ToString());
Repeater1.DataSource = da.EventHistory(pname, hidEventName.Value);
这篇关于如何将手风琴与中继器绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文