Hello All,
i honestly tried to find if this have been asked before but to no avail.
i have a user control that is bind-able to inside a GridTemplateColumn of a datagrid, it works fine and it displays the data, the problem is when the grid is sorted for example, all the data is lost.
i think i can solve this using a hidden control inside the usercontrol, but i am not sure yet, and i would like to know if there is something i am missing
to reproduce:
create user control:
User control code behind:
Page:
Page code behind:
i honestly tried to find if this have been asked before but to no avail.
i have a user control that is bind-able to inside a GridTemplateColumn of a datagrid, it works fine and it displays the data, the problem is when the grid is sorted for example, all the data is lost.
i think i can solve this using a hidden control inside the usercontrol, but i am not sure yet, and i would like to know if there is something i am missing
to reproduce:
create user control:
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="X3.ascx.vb" Inherits="X3" %> |
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> |
Partial Class X3 |
Inherits System.Web.UI.UserControl |
Private _X3 As String |
Public Property X3() As String |
Get |
Return _X3 |
End Get |
Set(ByVal value As String) |
_X3 = value |
End Set |
End Property |
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load |
Label1.Text = _X3 |
End Sub |
End Class |
Page:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ControlState.aspx.vb" Inherits="ControlState" %> |
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
<%@ Register Src="X3.ascx" TagName="X3" TagPrefix="uc1" %> |
<html xmlns="http://www.w3.org/1999/xhtml" > |
<head runat="server"> |
<title>Untitled Page</title> |
</head> |
<body> |
<form id="form1" runat="server"> |
<telerik:RadScriptManager ID="RadScriptManager1" runat="server"> |
</telerik:RadScriptManager> |
<div> |
<telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" AllowSorting="True" AutoGenerateColumns="False" EnableViewState ="true" > |
<MasterTableView> |
<RowIndicatorColumn> |
<HeaderStyle Width="20px" /> |
</RowIndicatorColumn> |
<ExpandCollapseColumn> |
<HeaderStyle Width="20px" /> |
</ExpandCollapseColumn> |
<Columns> |
<telerik:GridBoundColumn UniqueName="X1" DataField="X1" HeaderText="X1"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn UniqueName="X2" DataField="X2" HeaderText="X2"> |
</telerik:GridBoundColumn> |
<telerik:GridTemplateColumn UniqueName="X3" DataField="X3" HeaderText="X3" SortExpression="X3"> |
<ItemTemplate> |
<uc1:X3 ID="X3_1" runat="server" X3='<%# Eval("X3") %>' /> |
</ItemTemplate> |
</telerik:GridTemplateColumn> |
<telerik:GridBoundColumn UniqueName="X4" DataField="X4" HeaderText="X4"> |
</telerik:GridBoundColumn> |
</Columns> |
</MasterTableView> |
</telerik:RadGrid> |
</div> |
</form> |
</body> |
</html> |
Page code behind:
Imports Telerik.Web.UI |
Partial Class ControlState |
Inherits System.Web.UI.Page |
Private Sub RadGrid1_NeedDataSource(ByVal [source] As Object, _ |
ByVal e As GridNeedDataSourceEventArgs) _ |
Handles RadGrid1.NeedDataSource |
Dim list As New ArrayList |
For i As Integer = 0 To 4 |
Dim v As New D |
v.X1 = "V" & i.ToString & "_X1" |
v.X2 = "V" & i.ToString & "_X2" |
v.X3 = "V" & i.ToString & "_X3" |
v.X4 = "V" & i.ToString & "_X4" |
list.Add(v) |
Next |
RadGrid1.DataSource = list |
End Sub |
Private Class D |
Private _X1 As String |
Public Property X1() As String |
Get |
Return _X1 |
End Get |
Set(ByVal value As String) |
_X1 = value |
End Set |
End Property |
Private _X2 As String |
Public Property X2() As String |
Get |
Return _X2 |
End Get |
Set(ByVal value As String) |
_X2 = value |
End Set |
End Property |
Private _X3 As String |
Public Property X3() As String |
Get |
Return _X3 |
End Get |
Set(ByVal value As String) |
_X3 = value |
End Set |
End Property |
Private _X4 As String |
Public Property X4() As String |
Get |
Return _X4 |
End Get |
Set(ByVal value As String) |
_X4 = value |
End Set |
End Property |
End Class |
End Class |