Solved

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

Posted on 2011-02-15
3
2,381 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
ID: 34904117
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
ID: 34909128
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
ID: 34909623
thx
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Set cookies HttpOnly and Secure 4 113
Auto refresh part of an MVC5 View 7 61
Turn on intranet settings 1 41
designing in object programming 12 42
AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 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