如何使用C#与ASP.NET 4.5使用的LinkBut​​ton直放站 [英] How to use linkbutton in repeater using C# with ASP.NET 4.5

查看:190
本文介绍了如何使用C#与ASP.NET 4.5使用的LinkBut​​ton直放站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在asp.net我在数据库中包含的问题,提交和answers.On页面加载的问题只有我appear.now要使用的任何链接的日期表,上单击表中的数据指定show答案,迄今为止,无论是在文本框或标签,并在该链接的答案再次点击再次消失喜欢膨胀和收缩的点击。
这样,我在C#中使用什么编码呢?

In asp.net I have a table in database containing questions,date of submission and answers.On page load only questions appear.now i want to use any link which on clicking show answers and date specified in table data, either in textbox or label and clicking again on that link answer disappear again like expand and shrink on click. So what coding should i use for this in C#?

推荐答案

我相信你能处理的 ItemCommand的Repeater 事件。

I believe you could handle the ItemCommand event of the Repeater.

地方,你希望用户在Repeater的项目模板,点击链接LinkBut​​ton控件。这CommandName属性设置为有意义的事情,比如ShowAnswers​​。此外,ASPX标记内的Visible属性添加一个Label或TextBox控件到Repeater的项目模板,但设置为false。

Place a LinkButton control for the link that you want the user to click in the Repeater's item template. Set the CommandName property of this to something meaningful, like "ShowAnswers". Also, add a Label or TextBox control into the Repeater's item template, but set their Visible property to false within the aspx markup.

在C-背后的$ C $,ItemCommand事件处理程序检查中,如果 e.CommandName 的值等于您的命令(「ShowAnswers)。如果是这样,则查找该转发器项目中的答案和日期标签或文本框控件(通过 e.Item 访问)。当你找到他们,他们的Visible属性设置为true。

In the code-behind, within the ItemCommand event handler check if the value of e.CommandName equals your command ("ShowAnswers"). If so, then find the Label or TextBox controls for the answers and date within that Repeater item (accessed via e.Item). When you find them, set their Visible property to true.

请注意:你可以使用AJAX来为用户提供更完美的体验采取不同的方式,但这种方式可能是简单的初步实施

Note: you could take a different approach using AJAX to provide a more seamless experience for the user, but this way is probably simpler to implement initially.

我认为实施将是这个样子。免责声明:我没有测试此code

I think the implementation would look something like this. Disclaimer: I haven't tested this code.

code-背后:

void Repeater_ItemCommand(Object Sender, RepeaterCommandEventArgs e)
{
    if (e.CommandName == "ShowAnswers")
    {
        Control control;

        control = e.Item.FindControl("Answers");
        if (control != null)
            control.Visible = true;

        control = e.Item.FindControl("Date");
        if (control != null)
            control.Visible = true;
    }
}

ASPX标记:

ASPX Markup:

<asp:Repeater id="Repeater" runat="server" OnItemCommand="Repeater_ItemCommand">
  <ItemTemplate>
    <asp:LinkButton id="ShowAnswers" runat="server" CommandName="ShowAnswers" />
    <asp:Label id="Answers" runat="server" Text='<%# Eval("Answers") %>' Visible="false" />
    <asp:Label id="Date" runat="server" Text='<%# Eval("Date") %>' Visible="false" />
  </ItemTemplate>
</asp:Repeater>

这篇关于如何使用C#与ASP.NET 4.5使用的LinkBut​​ton直放站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆