如何在datalist控件中按按钮重定向到不同的页面 [英] how to redirect to different page by button in datalist control

查看:64
本文介绍了如何在datalist控件中按按钮重定向到不同的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们我有数据列表控件列出产品。

i在项目模板字段中有一个名为详细信息的按钮。

我的问题是如何使用这个按钮重定向到特定的产品详细信息页面?

因为我必须将它们重定向到多个页面。如果我添加respons.redirect它将重定向到所有产品的同一页面。

请帮帮我。





guys i have datalist control which lists the products.
i have one button in Item template field named "details".
my question is how can i use this button to redirect to specific product details page??
coz i have to redirect them to more then one page.if i add respons.redirect it will redirect to same page for all product.
please help me.


<asp:DataList ID="Productlist" runat="server" BackColor="White" <br />
                    BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" <br />
                    ForeColor="Black" GridLines="Horizontal" HorizontalAlign="Left" <br />
                    Width="570px" DataKeyField="ProductID" <br />
                    onitemcommand="Productlist_ItemCommand"><br />
                    <FooterStyle BackColor="#CCCC99" ForeColor="Black" /><br />
                    <HeaderStyle BackColor="#333333" Font-Bold="True" Font-Size="Medium" <br />
                        ForeColor="White" HorizontalAlign="Center" VerticalAlign="Middle" /><br />
                    <HeaderTemplate><br />
                        Products<br />
                    </HeaderTemplate><br />
                    <ItemTemplate><br />
                               <br />
                        <table style="width:100%;"><br />
                            <tr><br />
                                <td rowspan="5" width="30%"><br />
                                    <asp:Image ID="Image1" runat="server" <br />
                                        ImageUrl=''<%# Eval("ProductImagePath") %>'' /><br />
                                </td><br />
                                <td width="30%"><br />
                                     </td><br />
                                <td width="40%"><br />
                                    <asp:Label ID="Label4" runat="server" Text=''<%# Eval("ProductID") %>''></asp:Label><br />
                                </td><br />
                            </tr><br />
                            <tr><br />
                                <td width="30%"><br />
                                    ModelName:</td><br />
                                <td width="40%"><br />
                                    <asp:Label ID="Label1" runat="server" Text=''<%# Eval("ModelName") %>''></asp:Label><br />
                                </td><br />
                            </tr><br />
                            <tr><br />
                                <td width="30%"><br />
                                    ModelNo:</td><br />
                                <td width="40%"><br />
                                    <asp:Label ID="Label2" runat="server" Text=''<%# Eval("ModelNo") %>''></asp:Label><br />
                                </td><br />
                            </tr><br />
                            <tr><br />
                                <td width="30%"><br />
                                    UnitCost:</td><br />
                                <td width="40%"><br />
                                    <asp:Label ID="Label3" runat="server" Text=''<%# Eval("UnitCost") %>''></asp:Label><br />
                                </td><br />
                            </tr><br />
                            <tr><br />
                                <td align="left" valign="middle" width="30%"><br />
                                    <asp:Button ID="detailbtn" runat="server" Text="Details" /><br />
                                </td><br />
                                <td align="left" valign="middle" width="40%"><br />
                                    <asp:ImageButton ID="ImageButton1" runat="server" <br />
                                        ImageUrl="~/images/addtocart.jpg"  <br />
                                        CausesValidation="False" CommandName="select" /><br />
                                </td><br />
                            </tr><br />
                        </table><br />
                              <br />
                    </ItemTemplate><br />
                    <SelectedItemStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" /><br />
                </asp:DataList>

推荐答案

首先将命令名称分配给单击以重定向到特定页面的按钮。

接下来根据您的要求编写下面显示的代码并进行一些更改。在datalist的itemcommand事件中写入它。

First Assign the Command Name to the Button where you click to redirect to certain page.
And next write the below shown code as required to your requirement and make some changes.write it inside itemcommand event of datalist.
if (e.CommandName == "View")
        {
            
            DataList1.SelectedIndex = e.Item.ItemIndex;
            Label lblModelNo= (Label)e.Item.FindControl("lblModelNo");//lblModelNo your model no binded label ID

            //here check the condition of which model no i.e, either mobile,books etc.your model no will be in the label(lblModelNo) and then redirect it to required page.
            
        }





参考这个

使用DataList控件 [ ^ ]


my建议是使用下拉列表...输入该列表中的所有产品名称...

给用户选择选项他想知道哪些产品细节....

在按钮点击事件上写一个代码..检查用户选择的每个项目的条件...

ex:下拉列表包含

A

B

C



如果用户选择A和点击按钮

- >你只需在该事件中编写代码,如

if(item == A)

{

response.redirect(a.aspx);



}





像这样你可以只使用按钮点击事件重定向到任何页面
my suggestion is to use drop down list... enter all the product names in that list...
give a option to user to select the which product details he wants to know....
write a code on button click event .. check condition for every item that user selected...
ex: dropdownlist contain
A
B
C

if user select A and click the button
->you just write the code in that event like
if(item==A)
{
response.redirect("a.aspx");

}


Like this way you can redirect to any page using button click event only


这篇关于如何在datalist控件中按按钮重定向到不同的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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