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

[Solved] Edit access wrong row

1 Answer 66 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mic
Top achievements
Rank 1
Mic asked on 21 May 2009, 04:51 PM
I have a search function that searches the item inside the database and display the list of items in the rad grid.
The Grid has a edit (which generate by grid option). Everything is ok with the first page. When I click edit, it edits the right item.
When click to the second page, then click edit , the its edit the wrong item (keep edit the item on the first page instead of the second page).
for example
The grid show 25 items per page.
When click edit on the first item. It does the right item.
I go to the second page. Click on the 26th items. (first item of page 2). It show the edit form with the item to edit is the first one, not the 26th one.

Any ideas?

This is my search function:

protected void btnSearch_Click(object sender, EventArgs e)
    {
        String cmdString = null;
        if (lstCat.SelectedValue == "All")
        {
            cmdString = "Select * FROM tblFood WHERE " + searchString(txtSearch.Text);
            lblKeyword.Text = "";
        }
        else
        {
            cmdString = "Select * FROM tblFood WHERE (" + searchString(txtSearch.Text) + ") AND category = '" + lstCat.SelectedValue + "'";
            lblKeyword.Text = "" ;
        }
        SqlDataSourceFood.SelectCommand = cmdString;
        SqlDataSourceFood.DataBind();
        GridFood.DataBind();
    }

1 Answer, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 25 May 2009, 01:39 PM
Hi Mic,

The way you have implemented your search function indicates that you are trying to use Simple databinding. However, for complex operations such as Edit/Update you need to use Advanced data binding. I'd suggest that you bind the grid either declaratively or in the NeedDataSource event to the SqlDataSource object, then in the search function contruct the corresponding select command for the SqlDataSource and call RadGrid's rebind method:

protected void btnSearch_Click(object sender, EventArgs e)  
    {  
        String cmdString = null;  
        if (lstCat.SelectedValue == "All")  
        {  
            cmdString = "Select * FROM tblFood WHERE " + searchString(txtSearch.Text);  
            lblKeyword.Text = "";  
        }  
        else 
        {  
            cmdString = "Select * FROM tblFood WHERE (" + searchString(txtSearch.Text) + ") AND category = '" + lstCat.SelectedValue + "'";  
            lblKeyword.Text = "" ;  
        }  
        SqlDataSourceFood.SelectCommand = cmdString;  
        GridFood.Rebind();  
    }  
 
 
 

I hope this information helps.

Best Regards,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Mic
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Share this question
or