Hi All,
I have a radgrid with paging enabled. It has 2 template columns with textboxes.
Whenever i enter some values in these textboxes and go to next page , and come back on first page then the text that i typed earlier is lost.
I am maintaining this data in session. Please help .I need urgent help on this.
Thanks,
SK
SAMPLE Code below-
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadGrid ID="grChecklist1" runat="server" AutoGenerateColumns="false"
onneeddatasource="grChecklist1_NeedDataSource"
onpageindexchanged="grChecklist1_PageIndexChanged" >
<MasterTableView AllowPaging="true" AutoGenerateColumns="false" PageSize="5">
<Columns>
<telerik:GridTemplateColumn DataField="Number" HeaderText="Number" Visible="true">
<ItemTemplate>
<asp:TextBox ID="txtNumber" runat="server" Text='<%#Bind("Number")%>'/>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn DataField="TaskDescription" HeaderText="TaskDescription" Visible="true">
<ItemTemplate>
<asp:TextBox ID="txtTaskDescription" runat="server" Text='<%#Bind("TaskDescription")%>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
-------------------------------cs file code-------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadDetails();
}
}
private void LoadDetails()
{
DataTable dt = new DataTable();
dt.Columns.Add("Number",typeof(string));
dt.Columns.Add("TaskDescription", typeof(string));
dt.Rows.Add("1", "task1");
dt.Rows.Add("2", "task2");
dt.Rows.Add("3", "task3");
dt.Rows.Add("4", "task4");
dt.Rows.Add("5", "task5");
dt.Rows.Add("6", "task6");
dt.Rows.Add("7", "task7");
//grChecklist.DataSource = dt;
// grChecklist.DataBind();
Session["dt"] = dt;
}
private void RefreshSessionState()
{
DataTable dt = new DataTable();
dt.Columns.Add("Number", typeof(string));
dt.Columns.Add("TaskDescription", typeof(string));
foreach (GridDataItem item in grChecklist1.Items)
{
string number=(item.FindControl("txtNumber") as TextBox).Text;
string task = (item.FindControl("txtTaskDescription") as TextBox).Text;
dt.Rows.Add(number,task);
}
if (Session["dt"] != null)
Session.Remove("dt");
Session["dt"] = dt;
}
protected void grChecklist1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
// RefreshSessionState();
grChecklist1.DataSource = (DataTable)Session["dt"];
}
protected void grChecklist1_PageIndexChanged(object sender, GridPageChangedEventArgs e)
{
grChecklist1.AllowPaging = false;
grChecklist1.Rebind();
// RefreshSessionState();
grChecklist1.CurrentPageIndex = e.NewPageIndex;
grChecklist1.AllowPaging = true;
grChecklist1.Rebind();
}
}
I have a radgrid with paging enabled. It has 2 template columns with textboxes.
Whenever i enter some values in these textboxes and go to next page , and come back on first page then the text that i typed earlier is lost.
I am maintaining this data in session. Please help .I need urgent help on this.
Thanks,
SK
SAMPLE Code below-
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadGrid ID="grChecklist1" runat="server" AutoGenerateColumns="false"
onneeddatasource="grChecklist1_NeedDataSource"
onpageindexchanged="grChecklist1_PageIndexChanged" >
<MasterTableView AllowPaging="true" AutoGenerateColumns="false" PageSize="5">
<Columns>
<telerik:GridTemplateColumn DataField="Number" HeaderText="Number" Visible="true">
<ItemTemplate>
<asp:TextBox ID="txtNumber" runat="server" Text='<%#Bind("Number")%>'/>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn DataField="TaskDescription" HeaderText="TaskDescription" Visible="true">
<ItemTemplate>
<asp:TextBox ID="txtTaskDescription" runat="server" Text='<%#Bind("TaskDescription")%>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
-------------------------------cs file code-------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadDetails();
}
}
private void LoadDetails()
{
DataTable dt = new DataTable();
dt.Columns.Add("Number",typeof(string));
dt.Columns.Add("TaskDescription", typeof(string));
dt.Rows.Add("1", "task1");
dt.Rows.Add("2", "task2");
dt.Rows.Add("3", "task3");
dt.Rows.Add("4", "task4");
dt.Rows.Add("5", "task5");
dt.Rows.Add("6", "task6");
dt.Rows.Add("7", "task7");
//grChecklist.DataSource = dt;
// grChecklist.DataBind();
Session["dt"] = dt;
}
private void RefreshSessionState()
{
DataTable dt = new DataTable();
dt.Columns.Add("Number", typeof(string));
dt.Columns.Add("TaskDescription", typeof(string));
foreach (GridDataItem item in grChecklist1.Items)
{
string number=(item.FindControl("txtNumber") as TextBox).Text;
string task = (item.FindControl("txtTaskDescription") as TextBox).Text;
dt.Rows.Add(number,task);
}
if (Session["dt"] != null)
Session.Remove("dt");
Session["dt"] = dt;
}
protected void grChecklist1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
// RefreshSessionState();
grChecklist1.DataSource = (DataTable)Session["dt"];
}
protected void grChecklist1_PageIndexChanged(object sender, GridPageChangedEventArgs e)
{
grChecklist1.AllowPaging = false;
grChecklist1.Rebind();
// RefreshSessionState();
grChecklist1.CurrentPageIndex = e.NewPageIndex;
grChecklist1.AllowPaging = true;
grChecklist1.Rebind();
}
}