<
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.