I have a RadGrid whose datasource is set dynamically. I have set paging to true but once I click the next page my grid disappers, but appears again with the page selected once my tabchange event is fired twice. My grid gets populates based on the hierarchical tab thats selected. I have rebound my grid in pageindexchanged, but still my grid disappears....
I have placed the decalration of my grid below....
<telerik:RadGrid ID="RadGrid1" runat="server" OnDataBound="RadGrid1_DataBound" GridLines="None" OnItemCommand="RadGrid1_ItemCommand"
OnItemDataBound="RadGrid1_ItemDataBound" ShowHeader="false" OnItemCreated="RadGrid1_ItemCreated" AllowPaging="true" PageSize="6"
OnPageIndexChanged="RadGrid1_PageIndexChanged">
<MasterTableView TableLayout="Fixed" DataKeyNames="id">
<ItemTemplate>
<%# (((GridItem)Container).ItemIndex != 0)? "</td></tr></table>" : "" %>
<asp:Panel ID="ItemContainer" CssClass='<%# (((GridItem)Container).ItemType == GridItemType.Item)? "item" : "alternatingItem" %>'
runat="server">
<table cellpadding="0" cellspacing="0" border="0">
<tr valign="top">
<td>
<asp:ImageButton ID="thumbimage" runat="server" ImageUrl='<%# Bind("imagepath") %>' OnClientClick=<%# "javascript:player.sendEvent('LOAD','" + Eval("filepath") +"')" %> />
</td>
<td>
<asp:LinkButton ID="titlelinktab" runat="server" Text='<%# Bind("title") %>' OnClientClick=<%# "javascript:player.sendEvent('LOAD','" + Eval("filepath") +"')" %> ></asp:LinkButton><br />
<asp:LinkButton ID="downloadbutton" runat="server" Text="Download" CommandName="download" CommandArgument='<%#Eval("id")%>' /><br />
<asp:LinkButton ID="addbutton" runat="server" CommandName="addtoplaylist" CommandArgument='<%#Eval("id")%>'
Text="Add to Playlist" />
</td>
</tr>
</table>
</asp:Panel>
</ItemTemplate>
</MasterTableView>
</telerik:RadGrid>
This is how I bind my grid initially,
protected void populategrid(string language, string category, string subcategory)
{
SqlConnection conn;
SqlCommand comm;
conn = new SqlConnection(ConfigurationManager.ConnectionStrings["myconn"].ConnectionString);
comm = new SqlCommand("select id,title,subject_name,category,subcategory,language,filepath,imagepath from video " +
"where ((category=@category and language=@language and subcategory=@subcategory) and publishdate <= getdate())", conn);
comm.Parameters.Add("@category", SqlDbType.NVarChar, 20);
comm.Parameters["@category"].Value = category;
comm.Parameters.Add("@language", SqlDbType.NVarChar, 20);
comm.Parameters["@language"].Value = language;
comm.Parameters.Add("@subcategory", SqlDbType.NVarChar, 20);
comm.Parameters["@subcategory"].Value = subcategory;
conn.Open();
//OleDbDataReader reader = comm.ExecuteReader();
SqlDataReader reader = comm.ExecuteReader();
if (reader.HasRows)
{
RadGrid1.DataSource = reader;
RadGrid1.DataBind();
}
else
{
result.Text = "There are no records to be displayed in this category";
}
}
This is my pageindexchanged event
protected void RadGrid1_PageIndexChanged(object sender, GridPageChangedEventArgs e)
{
RadGrid1.CurrentPageIndex = e.NewPageIndex;
this.RadGrid1.Rebind();
}
I have placed the decalration of my grid below....
<telerik:RadGrid ID="RadGrid1" runat="server" OnDataBound="RadGrid1_DataBound" GridLines="None" OnItemCommand="RadGrid1_ItemCommand"
OnItemDataBound="RadGrid1_ItemDataBound" ShowHeader="false" OnItemCreated="RadGrid1_ItemCreated" AllowPaging="true" PageSize="6"
OnPageIndexChanged="RadGrid1_PageIndexChanged">
<MasterTableView TableLayout="Fixed" DataKeyNames="id">
<ItemTemplate>
<%# (((GridItem)Container).ItemIndex != 0)? "</td></tr></table>" : "" %>
<asp:Panel ID="ItemContainer" CssClass='<%# (((GridItem)Container).ItemType == GridItemType.Item)? "item" : "alternatingItem" %>'
runat="server">
<table cellpadding="0" cellspacing="0" border="0">
<tr valign="top">
<td>
<asp:ImageButton ID="thumbimage" runat="server" ImageUrl='<%# Bind("imagepath") %>' OnClientClick=<%# "javascript:player.sendEvent('LOAD','" + Eval("filepath") +"')" %> />
</td>
<td>
<asp:LinkButton ID="titlelinktab" runat="server" Text='<%# Bind("title") %>' OnClientClick=<%# "javascript:player.sendEvent('LOAD','" + Eval("filepath") +"')" %> ></asp:LinkButton><br />
<asp:LinkButton ID="downloadbutton" runat="server" Text="Download" CommandName="download" CommandArgument='<%#Eval("id")%>' /><br />
<asp:LinkButton ID="addbutton" runat="server" CommandName="addtoplaylist" CommandArgument='<%#Eval("id")%>'
Text="Add to Playlist" />
</td>
</tr>
</table>
</asp:Panel>
</ItemTemplate>
</MasterTableView>
</telerik:RadGrid>
This is how I bind my grid initially,
protected void populategrid(string language, string category, string subcategory)
{
SqlConnection conn;
SqlCommand comm;
conn = new SqlConnection(ConfigurationManager.ConnectionStrings["myconn"].ConnectionString);
comm = new SqlCommand("select id,title,subject_name,category,subcategory,language,filepath,imagepath from video " +
"where ((category=@category and language=@language and subcategory=@subcategory) and publishdate <= getdate())", conn);
comm.Parameters.Add("@category", SqlDbType.NVarChar, 20);
comm.Parameters["@category"].Value = category;
comm.Parameters.Add("@language", SqlDbType.NVarChar, 20);
comm.Parameters["@language"].Value = language;
comm.Parameters.Add("@subcategory", SqlDbType.NVarChar, 20);
comm.Parameters["@subcategory"].Value = subcategory;
conn.Open();
//OleDbDataReader reader = comm.ExecuteReader();
SqlDataReader reader = comm.ExecuteReader();
if (reader.HasRows)
{
RadGrid1.DataSource = reader;
RadGrid1.DataBind();
}
else
{
result.Text = "There are no records to be displayed in this category";
}
}
This is my pageindexchanged event
protected void RadGrid1_PageIndexChanged(object sender, GridPageChangedEventArgs e)
{
RadGrid1.CurrentPageIndex = e.NewPageIndex;
this.RadGrid1.Rebind();
}