Solved

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

Posted on 2011-02-15
3
2,386 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

808 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