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

[Solved] radGrid control displays blank grid after date parameter is changed

3 Answers 178 Views
Grid
This is a migrated thread and some comments may be shown as answers.
AAA
Top achievements
Rank 1
AAA asked on 05 Apr 2013, 03:00 PM

I have an existing app (written by a previous developer) that is calling a stored procedure that populates a RadGrid control. It populates fine the first time around.

However, when I change the date parameter, click "search" button, I get a blank RadGrid control. When I click search the second time, the grid is populated. When I walk through the code, I get an error message

Column 'ID' does not belong to table Table.

How can I resolve the issue of having to click search twice to display data ?


protected void btnSubmit_OnClick(object sender, EventArgs e)
{
    try
    {
        ViewState["newset"] = null;
        CreateDatasource();
        this.RadGrid1.DataBind();
        this.RadGrid1.CurrentPageIndex = 0;
        ViewState["newset"] = "new";   
         
        string idex = this.hdnindex.Value;
        if (idex != string.Empty)
            this.RadGrid1.MasterTableView.Items[int.Parse(idex)].Selected = true;
         
     }
     catch (Exception ex) {
        this.lblMessage.Text = ex.Message;
     }        
}
 
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    try
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            HyperLink hLink = (HyperLink)item["ViewHyperLink"].Controls[0];
            if (hLink != null)
                hLink.Attributes.Add("onclick", "selectMe('" + item.ItemIndex + "');");
        }
    }
    catch (Exception ex)
    {
        this.lblMessage.Text = ex.Message;
    }
}

In the code behind above, when this.RadGrid1.DataBind() is called, the code steps into `RadGrid1_ItemCreated` loops through the if statement a few times, them goes into the if statement, comes out of the function, and then the catch statement of btnSubmit is called, which displays the error message "Column ID does not belong to table Table".   

Any ideas on how to resolve this?

3 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 10 Apr 2013, 07:53 AM
Hello,

Most probably the problem comes from the fact that you are only databinding the Grid in the button click event.

When the Grid is recreated it does not have where to take the data from and that is why you get the exception. Could you share your full page source code along with the code-behind file content? Thus all the people who want to help you will have better understanding of your case.

Regards,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
AAA
Top achievements
Rank 1
answered on 10 Apr 2013, 01:32 PM
Is there a way to get a faster response to a forum thread? I think a response to a question 5 days after it was posted is a bit ridiculous.
0
AAA
Top achievements
Rank 1
answered on 11 Apr 2013, 02:19 PM
The code block where the databinding is occuring is below:

private void CreateDatasource()
    {
        List<KeyValuePair<string, string>> lstParams = new List<KeyValuePair<string, string>>();
        try
        {
            lstParams.Add(new KeyValuePair<string, string>("@AgreementId", Session["AgreementID"].ToString()));
            lstParams.Add(new KeyValuePair<string, string>("@ProviderKey", Session["ProviderKey"].ToString()));
            lstParams.Add(new KeyValuePair<string, string>("@ServiceDate", this.txtDOS.Text));
            lstParams.Add(new KeyValuePair<string, string>("@DriverId", this.txtDriverNumber.Text));
            lstParams.Add(new KeyValuePair<string, string>("@Member", this.txtMemberSearch.Text));
            lstParams.Add(new KeyValuePair<string, string>("@SKDecalId", this.txtDecals.Text));
            lstParams.Add(new KeyValuePair<string, string>("@Certified", FilterNum.ToString()));
 
            DataSet ds = cls.getDataset("GetMemberTrips",lstParams);
 
            this.RadGrid1.DataSource = ds.Tables[0];
            this.RadGrid1.DataBind();
        }
        catch (Exception ex)
        {
            this.lblMessage.Text = ex.Message;
        }
   }
Tags
Grid
Asked by
AAA
Top achievements
Rank 1
Answers by
Andrey
Telerik team
AAA
Top achievements
Rank 1
Share this question
or