如何在点击转发器的项目时重定向到另一个页面? [英] how to redirect to another page while click on item of a repeater?

查看:178
本文介绍了如何在点击转发器的项目时重定向到另一个页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我想当我点击转发器的任何项目时,它将重定向到另一个页面以及查询字符串..其值来自数据库(名称)。实际上当我点击我想要重定向到用户详细信息页面的任何项目及其用户信息时我想做什么。



以下是我的代码:

Now i want when i click on any item of repeater it will redirect to another page along with query string.. whose value comes from database like (name). Actually what i want to do when i click on any item i want to redirect to user detail-page along with its user information.

following is my code:

<asp:Repeater ID="repeator1" runat="server">
    <HeaderTemplate>


    </HeaderTemplate>
    <ItemTemplate>

    <table>

    <tr>
    <td>
   <asp:Label ID="name" runat="server"  Text='<%#Eval("Name")%>'></asp:Label>
    </td>
    <tr>
   <td>
 <asp:Image Width="100" ID="Image1" ImageUrl='<%# Bind("Logo", "~/Images/{0}") %>' runat="server" />
   </td>
    </tr>
    </tr>
    </table>
    </ItemTemplate>

    </asp:Repeater>









代码落后:







code behind:

protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(@"data source=#######;Integrated Security=true;initial catalog=#####");

        con.Open();
        SqlCommand cmd = new SqlCommand("select * from Allapps", con);
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(ds);
        repeator1.DataSource = ds;
        repeator1.DataBind();

}

推荐答案

您可以尝试使用命令参数来尝试使用repeater itemcommand事件并获取所选项目的数据或者可以通过转发器的findcontrol方法。然后你可以重定向到另一个页面。
may be you can try repeater itemcommand event and get data of selected item using command argument or may be by repeater's findcontrol method. then you can redirect to another page.


RepDetails_ItemDataBound(object sender, RepeaterItemEventArgs e)
{

if (e.Item.ItemType.ToString().ToLower() == "item")
{
LinkButton l = (LinkButton)e.Item.FindControl("LinkButton1");
l.PostBackUrl = "yourpage.aspx?title='" + l.Text + "'";
}
}


这篇关于如何在点击转发器的项目时重定向到另一个页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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