5 Answers, 1 is accepted
0
Shinu
Top achievements
Rank 2
answered on 21 Sep 2012, 01:03 PM
Hi,
In order to implement advanced features in RadGrid like paging, make sure that grid is binded using its NeedDataSource event. Here is the sample code.
aspx:
Also take a look in to the following demo.
Grid / Basic Paging
Thanks,
Shinu.
In order to implement advanced features in RadGrid like paging, make sure that grid is binded using its NeedDataSource event. Here is the sample code.
aspx:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AllowPaging
=
"true"
AutoGenerateColumns
=
"false"
PageSize
=
"4"
onneeddatasource
=
"RadGrid1_NeedDataSource"
>
<
PagerStyle
Mode
=
"NextPrevAndNumeric"
/>
. . .
</
telerik:RadGrid
>
Grid / Basic Paging
Thanks,
Shinu.
0
Swapnil
Top achievements
Rank 1
answered on 21 Sep 2012, 01:09 PM
Hey i am new to telerik
i dont know what is needdatasource event and how to use it can u please explain
Thank U
i dont know what is needdatasource event and how to use it can u please explain
Thank U
0
Accepted
Shinu
Top achievements
Rank 2
answered on 24 Sep 2012, 05:18 AM
Hi,
Thanks,
Shinu.
The NeedDataSource event fires in the following cases as explained in this documentation.
-
Immediately after On_Load if the grid has not yet been data-bound and there is no ViewState data. This means that if MasterTableView.EnableViewState has been set to false, grid will bind each time the page loads, not only the first time.
-
When a paging operation occurs.
-
When a sorting operation occurs.
-
When an edit command is fired.
You can attach this event and then bind the gird as shown below.
aspx:
<
telerik:RadGrid
ID
=
"RadGrid2"
runat
=
"server"
AutoGenerateColumns
=
"false"
AllowFilteringByColumn
=
"true"
AllowSorting
=
"true"
OnNeedDataSource
=
"RadGrid2_NeedDataSource"
>
<
MasterTableView
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"LastName"
UniqueName
=
"LastName"
HeaderText
=
"LastName"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
protected
void
RadGrid2_NeedDataSource(
object
sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
SqlConnection con1 =
new
SqlConnection(WebConfigurationManager.ConnectionStrings[
"NorthwindConnectionString3"
].ConnectionString);
SqlCommand cmd =
new
SqlCommand(
"SELECT top 5 * FROM [Orders]"
, con1);
SqlDataAdapter ad =
new
SqlDataAdapter(cmd);
DataSet ds =
new
DataSet();
ad.Fill(ds);
RadGrid2.DataSource = ds;
}
Thanks,
Shinu.
0
Swapnil
Top achievements
Rank 1
answered on 24 Sep 2012, 06:28 AM
Paging is done correctely
but another issue arises for this the code isnamespace Telerik
{
public partial class WebForm1 : System.Web.UI.Page
{
Entity ent = new Entity();
EMPLOYEE emp = new EMPLOYEE();
protected void Page_Load(object sender, EventArgs e)
{
}
public void BindGrid()
{
}
protected void btnsave_Click(object sender, EventArgs e)
{
ent.Insert_emp(txtname.Text, txtaddress.Text, Convert.ToInt32(txtdeptid.Text));
ent.SaveChanges();
//BindGrid();
gv1.DataBind();
}
protected void gv1_NeedDataSource(object sender, Web.UI.GridNeedDataSourceEventArgs e)
{
//BindGrid();
var query = from employee in ent.EMPLOYEEs
select new
{
ID = employee.ID,
NAME = employee.NAME,
ADDRESS = employee.ADDRESS,
DEPTID = employee.DEPTID
};
gv1.DataSource = query;
//gv1.DataBind();
}
}
}
previouslu i had method BindGrid() to load record after addition quickly but now i dont have that method i moved that code into your event now how can i insert data and load grid without postback
please help.
but another issue arises for this the code isnamespace Telerik
{
public partial class WebForm1 : System.Web.UI.Page
{
Entity ent = new Entity();
EMPLOYEE emp = new EMPLOYEE();
protected void Page_Load(object sender, EventArgs e)
{
}
public void BindGrid()
{
}
protected void btnsave_Click(object sender, EventArgs e)
{
ent.Insert_emp(txtname.Text, txtaddress.Text, Convert.ToInt32(txtdeptid.Text));
ent.SaveChanges();
//BindGrid();
gv1.DataBind();
}
protected void gv1_NeedDataSource(object sender, Web.UI.GridNeedDataSourceEventArgs e)
{
//BindGrid();
var query = from employee in ent.EMPLOYEEs
select new
{
ID = employee.ID,
NAME = employee.NAME,
ADDRESS = employee.ADDRESS,
DEPTID = employee.DEPTID
};
gv1.DataSource = query;
//gv1.DataBind();
}
}
}
previouslu i had method BindGrid() to load record after addition quickly but now i dont have that method i moved that code into your event now how can i insert data and load grid without postback
please help.
0