Iam using Radgrid for my ASP.Net project.
I want to design,bound ,bind and create events for my grid by program.
for ex in my design i will have
<telerik:radgrid ID="RadGrid1" runat="server" >
</telerik:radgrid>
In page init i define all bound columns and design of grid and create a event for the grid for ex.
protected void Page_Init(object source, System.EventArgs e)
{
Loadprogramaticgrid();
RadGrid1.NeedDataSource += new GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource);
}
private void Loadprogramaticgrid()
{
RadGrid1.MasterTableView.DataKeyNames = new string[] { "username" };
RadGrid1.Skin = "Default";
RadGrid1.Width = Unit.Percentage(100);
RadGrid1.AutoGenerateColumns = false;
//Add columns
GridBoundColumn boundColumn;
boundColumn = new GridBoundColumn();
boundColumn.DataField = "username";
boundColumn.HeaderText = "username";
RadGrid1.MasterTableView.Columns.Add(boundColumn);
boundColumn = new GridBoundColumn();
boundColumn.DataField = "firstname";
boundColumn.HeaderText = "firstname";
RadGrid1.MasterTableView.Columns.Add(boundColumn);
boundColumn = new GridBoundColumn();
boundColumn.DataField = "lastname";
boundColumn.HeaderText = "lastname";
RadGrid1.MasterTableView.Columns.Add(boundColumn);
}
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
RadGrid1.DataSource = loaddata();
}
and i have a Button and in button click i rebind the grid as
protected void Button1_Click(object sender, EventArgs e)
{
RadGrid1.Rebind();
}
now the problem is for first time the grid binds and display the data in grid.
When i click the button the grid is not binding correctly.
i have attached the image for more referance.