Solved

Telerik RadGrid control - loop through information and / or identify selected info

Posted on 2011-02-15
3
2,378 Views
Last Modified: 2012-05-11
I need someone familiar with Telerik RadGrid controls to help me.

Or, if you are not familiar, but are willing to help me troubleshoot, that is fine also.

Essentially, I have an event that gets raised when a "Buy" button is pressed.

The event that is raised (and internal C# code) looks like this:

    protected void rgCourseSelect_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        switch (e.CommandName)
        {
            case "ClearSelection":
                {
                    string isbn = (e.Item.FindControl("lblDataKey") as Label).Text;
                    //remove from cart
                }
                break;
            case "OOS":
                {
                    //Response.Redirect("~/Info/OutOfStock.aspx");
                }
                break;
            case "Used":
                try
                {

                    Telerik.Web.UI.RadGrid myradView = source as Telerik.Web.UI.RadGrid;

                    //RadGrid1.SelectedItems[0].OwnerTableView.DataKeyValues[RadGrid1.SelectedItems[0].ItemIndex]["CustomerID"]

                    e.Item.BorderStyle = BorderStyle.Dashed;
                    e.Item.BorderColor = System.Drawing.Color.LightGoldenrodYellow;
                    e.Item.BorderWidth = 2;

                    string usedprice = (e.Item.FindControl("lblUsedPrice") as Label).Text;

                    string title = (e.Item.FindControl("lblTitle") as Label).Text;
                    string isbn = (e.Item.FindControl("lblDataKey") as Label).Text;
                    string type = "Used";
                    double fusedprice = Convert.ToDouble(usedprice);
                    //Telerik.Web.UI.RadGrid myradView = source as Telerik.Web.UI.RadGrid;
                    string coursedetail = (myradView.Parent.FindControl("lblDescription") as Label).Text;

                    string newused = "Used";
                    int qty = 1;

                    ThemeAwareImageButton tmpUsedButton = e.Item.FindControl("imgAddToCartUsed") as ThemeAwareImageButton;
                    ThemeAwareImageButton tmpNewButton = e.Item.FindControl("imgAddToCartNew") as ThemeAwareImageButton;
                    ThemeAwareImageButton tmpRentalButton = e.Item.FindControl("imgAddToCartRental") as ThemeAwareImageButton;
                    ThemeAwareImageButton tmpEbookButton = e.Item.FindControl("imgAddToCartEbook") as ThemeAwareImageButton;
                    
                    if (tmpNewButton.CommandName != "OOS")
                        tmpNewButton.ImageUrl = "cart-buy.gif";
                    if (tmpRentalButton.CommandName != "OOS")
                        tmpRentalButton.ImageUrl = "cart-buy.gif";
                    if (tmpEbookButton.CommandName != "OOS")
                        tmpEbookButton.ImageUrl = "cart-buy.gif";
                    if (tmpUsedButton.CommandName != "OOS")
                        tmpUsedButton.ImageUrl = "cart-buy.gif";

                    tmpUsedButton.ImageUrl = "bought-check.gif";




                    AddItemsToCart(isbn, title, coursedetail, fusedprice, qty, newused, type);



                }
                catch (Exception)
                {

                }
                break;
            case "New":
                try
                {

                    string newprice = (e.Item.FindControl("lblNewPrice") as Label).Text;
                    string title = (e.Item.FindControl("lblTitle") as Label).Text;
                    string isbn = (e.Item.FindControl("lblDataKey") as Label).Text; string type = "New";
                    double fnewprice = Convert.ToDouble(newprice);
                    Telerik.Web.UI.RadGrid myradView = source as Telerik.Web.UI.RadGrid;
                    string coursedetail = (myradView.Parent.FindControl("lblDescription") as Label).Text;

                    string newused = "New";
                    int qty = 1;

                    ThemeAwareImageButton tmpUsedButton = e.Item.FindControl("imgAddToCartUsed") as ThemeAwareImageButton;
                    ThemeAwareImageButton tmpNewButton = e.Item.FindControl("imgAddToCartNew") as ThemeAwareImageButton;
                    ThemeAwareImageButton tmpRentalButton = e.Item.FindControl("imgAddToCartRental") as ThemeAwareImageButton;
                    ThemeAwareImageButton tmpEbookButton = e.Item.FindControl("imgAddToCartEbook") as ThemeAwareImageButton;



                    if (tmpRentalButton.CommandName != "OOS")
                        tmpRentalButton.ImageUrl = "cart-buy.gif";
                    if (tmpEbookButton.CommandName != "OOS")
                        tmpEbookButton.ImageUrl = "cart-buy.gif";
                    if (tmpUsedButton.CommandName != "OOS")
                        tmpUsedButton.ImageUrl = "cart-buy.gif";


                    tmpNewButton.ImageUrl = "bought-check.gif";




                    AddItemsToCart(isbn, title, coursedetail, fnewprice, qty, newused, type);

                }
                catch (Exception)
                {
                }
                break;
            case "Ebook":
                try
                {


                    string ebookprice = (e.Item.FindControl("lblEbookPrice") as Label).Text;

                    string title = (e.Item.FindControl("lblTitle") as Label).Text;
                    string isbn = (e.Item.FindControl("lblDataKey") as Label).Text;
                    string type = "Ebook";
                    double fusedprice = Convert.ToDouble(ebookprice);
                    Telerik.Web.UI.RadGrid myradView = source as Telerik.Web.UI.RadGrid;
                    string coursedetail = (myradView.Parent.FindControl("lblDescription") as Label).Text;

                    string newused = "Ebook";
                    int qty = 1;

                    ThemeAwareImageButton tmpUsedButton = e.Item.FindControl("imgAddToCartUsed") as ThemeAwareImageButton;
                    ThemeAwareImageButton tmpNewButton = e.Item.FindControl("imgAddToCartNew") as ThemeAwareImageButton;
                    ThemeAwareImageButton tmpRentalButton = e.Item.FindControl("imgAddToCartRental") as ThemeAwareImageButton;
                    ThemeAwareImageButton tmpEbookButton = e.Item.FindControl("imgAddToCartEbook") as ThemeAwareImageButton;


                    if (tmpNewButton.CommandName != "OOS")
                        tmpNewButton.ImageUrl = "cart-buy.gif";
                    if (tmpRentalButton.CommandName != "OOS")
                        tmpRentalButton.ImageUrl = "cart-buy.gif";

                    if (tmpUsedButton.CommandName != "OOS")
                        tmpUsedButton.ImageUrl = "cart-buy.gif";

                    tmpEbookButton.ImageUrl = "bought-check.gif";



                    AddItemsToCart(isbn, title, coursedetail, fusedprice, qty, newused, type);



                }
                catch { }
                break;
            case "Rental":
                try
                {


                    string rentalPrice = (e.Item.FindControl("lblRentalPrice") as Label).Text;

                    string title = (e.Item.FindControl("lblTitle") as Label).Text;
                    string isbn = (e.Item.FindControl("lblDataKey") as Label).Text;
                    string type = "Rental";
                    double fusedprice = Convert.ToDouble(rentalPrice);
                    Telerik.Web.UI.RadGrid myradView = source as Telerik.Web.UI.RadGrid;
                    string coursedetail = (myradView.Parent.FindControl("lblDescription") as Label).Text;

                    string newused = "Rental";
                    int qty = 1;

                    ThemeAwareImageButton tmpUsedButton = e.Item.FindControl("imgAddToCartUsed") as ThemeAwareImageButton;
                    ThemeAwareImageButton tmpNewButton = e.Item.FindControl("imgAddToCartNew") as ThemeAwareImageButton;
                    ThemeAwareImageButton tmpRentalButton = e.Item.FindControl("imgAddToCartRental") as ThemeAwareImageButton;
                    ThemeAwareImageButton tmpEbookButton = e.Item.FindControl("imgAddToCartEbook") as ThemeAwareImageButton;



                    if (tmpNewButton.CommandName != "OOS")
                        tmpNewButton.ImageUrl = "cart-buy.gif";

                    if (tmpEbookButton.CommandName != "OOS")
                        tmpEbookButton.ImageUrl = "cart-buy.gif";
                    if (tmpUsedButton.CommandName != "OOS")
                        tmpUsedButton.ImageUrl = "cart-buy.gif";

                    tmpRentalButton.ImageUrl = "bought-check.gif";


                    AddItemsToCart(isbn, title, coursedetail, fusedprice, qty, newused, type);



                }
                catch { }
                break;

            default:
                break;
        }

    }

Open in new window



Right now my focus is on the case of "Used".

string usedprice = (e.Item.FindControl("lblUsedPrice") as Label).Text;
string title = (e.Item.FindControl("lblTitle") as Label).Text;
string isbn = (e.Item.FindControl("lblDataKey") as Label).Text;
     
After these lines run, the variables "usedprice", "title" and "isbn" are all empty, although they clearly are there on the screen.


I believe the values are there, I just think that the way I am trying to obtain the values is not working right.


TIA for your help, folks!


Tom    
0
Comment
Question by:knowlton
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
SAMIR BHOGAYTA earned 500 total points
Comment Utility
Hi, Can you wait for two days, because I have all the video tutorials of the Telerik Rad Controls. I will try to upload on my blog as early as possible. It is very helpful to you for solving this problem.
0
 
LVL 5

Author Comment

by:knowlton
Comment Utility
Late yesterday I just barely solved this....so no rush....I think you can just let this go for now.

I will post my solution in a little while.

Essentially the "EnableViewState" needs to be TRUE or the information does not show-up.


0
 
LVL 5

Author Closing Comment

by:knowlton
Comment Utility
thx
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now