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

Rebind not working

6 Answers 105 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shamim
Top achievements
Rank 1
Shamim asked on 25 Aug 2010, 04:41 PM
Here is my grid:

<

 

telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"

 

 

 

 

Height="100px" Width="600px" >

 

 

 

<MasterTableView AutoGenerateColumns="false" >

 

 

 

<Columns>

 

 

<telerik:GridBoundColumn DataField="ContactName" DataType="System.String"

 

 

HeaderText="Contact Name" ReadOnly="True"

 

 

>

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="Title" DataType="System.String"

 

 

HeaderText="Title" ReadOnly="True"

 

 

>

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="Email" DataType="System.String"

 

 

HeaderText="Email" ReadOnly="True"

 

 

>

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="Phone" DataType="System.String"

 

 

HeaderText="Phone" ReadOnly="True"

 

 

>

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="Fax" DataType="System.String"

 

 

HeaderText="Fax" ReadOnly="True"

 

 

>

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="ContactType" DataType="System.String"

 

 

HeaderText="Contact Type" ReadOnly="True"

 

 

>

 

 

</telerik:GridBoundColumn>

 

 

</Columns>

 

 

 

</MasterTableView>

 

 

<ClientSettings>

 

 

<Scrolling AllowScroll="True" UseStaticHeaders="True" />

 

 

</ClientSettings>

 

 

</telerik:RadGrid>

 

 

 

 

</td>

 

 

</tr>

 

 

</table>

 


Here is the click event:

 

protected void btnRecord_Click(object sender, EventArgs e)

 

{

RadGrid1.DataSource =

null;

 

RadGrid1.Rebind();

 

}


and down below is the needdatasource method:

protected

 

void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)

 

{

 

Contact curContact = new Contact();

 

curContact.ContactName = TextBox1.Text;

curContact.Title = TextBox2.Text;

curContact.Email = TextBox3.Text;

curContact.Phone = TextBox4.Text;

curContact.Fax = TextBox5.Text;

 

if (Session["ContactType"] != null)

 

{

curContact.ContactType = Session[

"ContactType"].ToString();

 

}

 

 

DataTable dt = new DataTable();

 

dt.Columns.Add(

"ContactName");

 

dt.Columns.Add(

"Title");

 

dt.Columns.Add(

"Email");

 

dt.Columns.Add(

"Phone");

 

dt.Columns.Add(

"Fax");

 

dt.Columns.Add(

"ContactType");

 

dt.Rows.Add(curContact.ContactName, curContact.Title, curContact.Email, curContact.Phone, curContact.Fax,

curContact.ContactType);

RadGrid1.DataSource = dt;

}


The binding occurs and populates the grid when the page loads for the first time. But in the button click event the rebind forces the needdatasource event to fire but does not do any binding with the new passed values.

Please help. Thanks.

6 Answers, 1 is accepted

Sort by
0
Cori
Top achievements
Rank 2
answered on 25 Aug 2010, 06:50 PM
Remove the call, RadGrid1.DataSource = null, since it's not needed to force the RadGrid to rebind and see if that helps.
0
Shamim
Top achievements
Rank 1
answered on 25 Aug 2010, 08:36 PM
took the null off...still same issue...
0
Princy
Top achievements
Rank 2
answered on 26 Aug 2010, 03:16 PM
Hello Shamin,

One suggestion would be storing the DataTable in a globally accessible location like session and populating the grid using the saved DataTable.

Thanks,
Princy.
0
Shamim
Top achievements
Rank 1
answered on 26 Aug 2010, 05:44 PM
The data table already comes from the session and I checked the debugger to make sure that it is getting the data. The funny thing is that the rebind method does hit the event for onneeddatasource and goes all the way down to where we set up the datasource, but then the grid remains completely unchanged and stays their with the value of the initial page load...pls suggest... 
0
Amit Dua
Top achievements
Rank 1
answered on 26 Aug 2010, 11:15 PM
can you please provide full code or page load code
0
Shamim
Top achievements
Rank 1
answered on 27 Aug 2010, 01:29 AM
There is really no code in the page load. The radgrid is in the aspx page with the onneeddatasource even assigned to certain method. Here is the method below:

 

protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)

 

{

 

Contact curContact = new Contact();

 

curContact.ContactName = TextBox1.Text;

curContact.Title = TextBox2.Text;

curContact.Email = TextBox3.Text;

curContact.Phone = TextBox4.Text;

curContact.Fax = TextBox5.Text;

 

if (Session["ContactType"] != null)

 

{

curContact.ContactType = Session[

"ContactType"].ToString();

 

}

 

 

DataTable dt = new DataTable();

 

dt.Columns.Add(

"ContactName");

 

dt.Columns.Add(

"Title");

 

dt.Columns.Add(

"Email");

 

dt.Columns.Add(

"Phone");

 

dt.Columns.Add(

"Fax");

 

dt.Columns.Add(

"ContactType");

 

dt.Rows.Add(curContact.ContactName, curContact.Title, curContact.Email, curContact.Phone, curContact.Fax,

curContact.ContactType);

RadGrid1.DataSource =

null;

 

RadGrid1.DataSource = dt;

}

Now I have a click event for a button that has the following code only:

 

 

protected void btnRecord_Click(object sender, EventArgs e)

 

{

RadGrid1.Rebind();

 

 

}

page load does not have any code at all in there. Also in the page there is no ajax manager or ajax manager proxy. When the page loads initially the grid gets populated with whatever session variable values we got. Now with the click event the session value gets changed and then it again fires the RadGrid1_NeedDataSource method. But that does not make any change to the radgrid. Looks like the radgrid does not have any idea on whats going on during rebind. If this makes sense, let me know. Thanks.

Tags
Grid
Asked by
Shamim
Top achievements
Rank 1
Answers by
Cori
Top achievements
Rank 2
Shamim
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Amit Dua
Top achievements
Rank 1
Share this question
or