This is a migrated thread and some comments may be shown as answers.

first firing itemcommand and sort to default state

3 Answers 51 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Spire
Top achievements
Rank 1
Spire asked on 30 Jun 2011, 08:22 PM
Hi,

I'm having some small problems with RadGrid.

Issue 1:
Here is an example page
http://dev2.spireweb.no/resultat.aspx?pid=15&rb=1&type=simpel&q=test
When I fill in a value in the textbox the first time and then I click "Kjøp" then it does not find the value of the textbox, and just add 1 item to cart (handlevogn), but the second time I click "kjøp" it finds the value enter in the textbox.
Here is my ItemCommand code:
protected void radResult_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
{
    switch (e.CommandName)
    {
        case "AddToCart":
            int test = e.Item.DataSetIndex;
            TextBox txtQuantity = (TextBox)(e.Item.FindControl("txtQuantity"));
            if (txtQuantity.Text.Length > 0)
                ShoppingCart.GetCurrentUsersCart.AddItem(int.Parse(e.CommandArgument.ToString()), int.Parse(txtQuantity.Text.ToString()));
            else
                ShoppingCart.GetCurrentUsersCart.AddItem(int.Parse(e.CommandArgument.ToString()), 1);
            txtQuantity.Text = "";
             
            RadAjaxManager1.ResponseScripts.Add("javascript:updateCart();");
            //RadAjaxManager1.ResponseScripts.Add(string.Format("alert('Hello from the server! Server time is {0}');", DateTime.Now.ToLongTimeString()));
            break;
    }
}

Why do this happen?

Issue 2:
Who can I "reset" the sort, so it goes back to first sort state?
Here is an example page:
http://dev2.spireweb.no/resultat.aspx?pid=15&rb=2&type=simpel&q=test
If I click "Vis treff A-Å" how can I go back to the sort state the radgrid started with?

Thanks in advaned...

3 Answers, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 06 Jul 2011, 10:11 AM
Hello,

 Issue 1: The code snippet looks OK. Can you specify whether the textbox is not found at all or only the text inside it is empty. Another option to find the control is to directly access the cell for that column and then the controls inside it as shown in this help topic:

Table cell = (e.Item as GridDataItem)["ColumnUniqueName"];
// then you can access
cell.Controls[0] as TextBox
//or
cell.FindControl("txtQuantity");

Issue 2: You can reset the sorting for the grid by clearing the sort expressions and rebinding the grid after that. Also the grid supports two modes of sorting - the default one with three states (Asc, Desc and Default ) and the other one only with two states (Asc, Desc) You can configure them through the AllowNaturalSort property. More information is available here. Here is a sample code on how to clear the sort expressions:
RadGrid1.MasterTableView.SortExpressions.Clear();
RadGrid1.Rebind();

 If the issue persists I will appreciate if you could post he grid declaration as well.Greetings,
Marin
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Spire
Top achievements
Rank 1
answered on 06 Jul 2011, 10:13 PM
Hi again,

Thanks for your reply

Issue 1:
It seems to find the textbox, but text is empty. Only the on the first itemcommand event, the itemcommands after works.
If I use tried this:
TableCell cell = (e.Item as GridDataItem)["Antall"];
TextBox txtQuantity = cell.Controls[0] as TextBox;
I get this error: Object reference not set to an instance of an object.

If I use tried this:
TableCell cell = (e.Item as GridDataItem)["Antall"];
TextBox txtQuantity = (TextBox)cell.FindControl("txtQuantity");
It finds the textbox, but the text is empty. Only the on the first itemcommand event, the itemcommands after works.

Issue 2: Solved

0
Accepted
Marin
Telerik team
answered on 07 Jul 2011, 12:55 PM
Hi,

 Can you provide the grid declaration and code-behind? It looks like for some reason the text is not sent to the server the first time. You should check whether you do not have any additional logic or setting (e.g. ajax) that can cause this behaviour.
You can have a look at the sample page showing similar working scenario.

Best wishes,
Marin
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Grid
Asked by
Spire
Top achievements
Rank 1
Answers by
Marin
Telerik team
Spire
Top achievements
Rank 1
Share this question
or