Click here to Skip to main content
15,881,516 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,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>
Posted
Updated 7-Mar-13 22:23pm
v3
Comments
Nandakishore G N 8-Mar-13 1:17am    
are you maintaining page list in your database..because you want to redirect it to respective details page.it is better if you paste the code what you have done till now.
pradiprenushe 8-Mar-13 3:05am    
How you are going to decide which page you have to redirect.
rrjoshi2321992 8-Mar-13 4:31am    
i m generating datalist from my data base.
EX: if there are 2 listitems like "mobile" and "books". if i click detail button of mobile then it should redirect me to "mobile.aspx" and if i click detail button of books then it should redirect me to "books.aspx". But as button is in itemtemplate it only redirect me to one page insted of every product specific page.:(
Nandakishore G N 8-Mar-13 4:37am    
you are maintaining the modelno, then in the itemcommand receive the model no from the label and match the condition of which model and then redirect it to the respective pages.
rrjoshi2321992 8-Mar-13 4:42am    
can u post the code sample 4 it.pls:)

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.
C#
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.
            
        }


refer this
Working with the DataList Control[^]
 
Share this answer
 
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900