Hello,
I am using a grid to load a dataview similar to your WebMail example. I can select the first row and load dataview on page load. I can load dataview on row selection, but I cannot figure out how to load first row on grid sort function. I have tried using pre render which works, but then row selected command does not work. On your WebMail example you use the grid as your parameter value for the link data source of the dataview. I am using a custom dataset from data layer, so cannot use the same way. How can I get similar functionality? If I use a sessin variable it never loads new selection, but if I put selected grid value in textbox on client side, then get value I can load dataview except on sort.
I am using a grid to load a dataview similar to your WebMail example. I can select the first row and load dataview on page load. I can load dataview on row selection, but I cannot figure out how to load first row on grid sort function. I have tried using pre render which works, but then row selected command does not work. On your WebMail example you use the grid as your parameter value for the link data source of the dataview. I am using a custom dataset from data layer, so cannot use the same way. How can I get similar functionality? If I use a sessin variable it never loads new selection, but if I put selected grid value in textbox on client side, then get value I can load dataview except on sort.
Imports
System
Imports
System.Data
Imports
Message
Imports
Telerik.Web.UI
Partial
Class
Messages
Inherits
System.Web.UI.Page
Protected
m
As
New
Message
Dim
isSelected
As
Boolean
Sub
Page_Load(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
Handles
MyBase
.Load
If
Not
IsPostBack
Then
Session(
"SelectedView"
) =
"Inbox"
RadGrid1.Rebind()
SelectFirstGridRow()
LoadMessage()
Else
LoadMessage()
End
If
End
Sub
Protected
Sub
RtvMessageslNodeClick(
ByVal
sender
As
Object
,
ByVal
e
As
Telerik.Web.UI.RadTreeNodeEventArgs)
Handles
RtvMessages.NodeClick
Select
Case
e.Node.Text
Case
"Inbox"
Session(
"SelectedView"
) =
"Inbox"
Exit
Select
Case
"Sent"
Session(
"SelectedView"
) =
"Sent"
Exit
Select
Case
"Agency"
Session(
"SelectedView"
) =
"Deleted"
Exit
Select
End
Select
RadGrid1.Rebind()
End
Sub
Protected
Sub
RadGrid1_NeedDataSource(
ByVal
source
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridNeedDataSourceEventArgs)
Handles
RadGrid1.NeedDataSource
Dim
listtype
As
String
'= "Inbox"
listtype = RtvMessages.SelectedNode.Text
'testout.Text = listtype
Select
Case
listtype
Case
"Sent"
RadGrid1.MasterTableView.GetColumn(
"ToUserFullName"
).Visible =
True
RadGrid1.MasterTableView.GetColumn(
"FromUserFullName"
).Visible =
False
Case
"Deleted"
RadGrid1.MasterTableView.GetColumn(
"FromUserFullName"
).Visible =
True
RadGrid1.MasterTableView.GetColumn(
"ToUserFullName"
).Visible =
False
Case
Else
RadGrid1.MasterTableView.GetColumn(
"FromUserFullName"
).Visible =
True
RadGrid1.MasterTableView.GetColumn(
"ToUserFullName"
).Visible =
False
End
Select
Dim
errors
As
String
=
""
RadGrid1.DataSource = Message.GetMessageList_outlookformat(Membership.GetUser(User.Identity.Name).ProviderUserKey, listtype, errors)
'testout.Text = errors
End
Sub
Protected
Sub
RadGrid1_RowSelected(
ByVal
source
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridNeedDataSourceEventArgs)
Session(
"SelectedMessage"
) = RadGrid1.SelectedValue.ToString
LoadMessage()
Dim
errors
As
String
=
""
End
Sub
Sub
Checkisnew(
ByVal
sender
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridItemEventArgs)
Handles
RadGrid1.ItemDataBound
If
TypeOf
e.Item
Is
Telerik.Web.UI.GridDataItem
Then
Dim
checkrow
As
DataRowView
checkrow = e.Item.DataItem
Dim
i
As
New
HtmlImage
i = e.Item.FindControl(
"mailicon"
)
'Dim i2 As New HtmlImage
'i2 = e.Item.FindControl("replyicon")
If
checkrow.Row(
"IsNew"
)
Then
i.Src =
"images/icon-msg-unread.gif"
ElseIf
checkrow.Row(
"RepliedTo"
)
Then
i.Src =
"images/icon-msg-reply.gif"
ElseIf
checkrow.Row(
"Forwarded"
)
Then
i.Src =
"images/icon-msg-forward.gif"
Else
i.Src =
"images/icon-msg-read.gif"
End
If
'If checkrow.Row("RepliedTo") Then
' i2.Src = "images/reply.gif"
'Else
' i2.Src = "images/spacer.gif"
' i2.Visible = False
'End If
'i2 = e.Item.FindControl("forwardicon")
'If checkrow.Row("Forwarded") Then
' i2.Src = "images/forward.gif"
' i2.Style.Add("margin-left", "2px")
'Else
' i2.Src = "images/spacer.gif"
' i2.Visible = False
'End If
Dim
dt
As
DateTime = checkrow(
"DateCreated"
)
e.Item.Cells(7).Text = dt.ToShortDateString &
" "
& dt.ToShortTimeString
End
If
End
Sub
Protected
Sub
RadGrid1_PreRender(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
Handles
RadGrid1.PreRender
'If (RadGrid1.MasterTableView.Items.Count > 0) Then
' If RadGrid1.SelectedItems.Count = 0 Then
' RadGrid1.MasterTableView.Items(0).Selected = True
' Session("SelectedMessage") = RadGrid1.SelectedValue.ToString
' LoadMessage()
' Else
' LoadMessage()
' End If
'End If
End
Sub
Private
Sub
SelectFirstGridRow()
Dim
firstDataItem
As
GridDataItem = RadGrid1.Items.OfType(Of GridDataItem).FirstOrDefault()
If
firstDataItem IsNot
Nothing
Then
firstDataItem.Selected =
True
If
Session(
"SelectedMessage"
)
Is
Nothing
Then
Session(
"SelectedMessage"
) = RadGrid1.SelectedValue.ToString
End
If
End
If
End
Sub
Sub
Deletemessage(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
m.Load(RadGrid1.SelectedValue)
m.MarkForDeletion()
Dim
intpage
As
Integer
intpage = RadGrid1.CurrentPageIndex
RadGrid1.Rebind()
RadGrid1.CurrentPageIndex = intpage
End
Sub
Sub
LoadMessage()
Dim
messageGuidIn
As
String
Dim
guidin
As
Guid
Dim
mv
As
DetailsView = DetailsView1
Dim
ds
As
DataSet
If
RadGrid1.Items.Count > 0
Then
Dim
selectedTextBox
As
RadTextBox =
DirectCast
(
DirectCast
(RadToolBar1.FindButtonByCommandName(
"selectedText"
), RadToolBarButton).FindControl(
"RadTextBox1"
), RadTextBox)
If
selectedTextBox.Text =
String
.Empty
Then
messageGuidIn = RadGrid1.SelectedValue.ToString
Else
messageGuidIn = selectedTextBox.Text
End
If
guidin =
New
Guid(messageGuidIn)
ds = Message.GetMessage(guidin)
If
ds.Tables.Count > 0
Then
m.Load(guidin)
If
m.IsNew
Then
m.ChangeIsNew()
End
If
End
If
mv.DataSource = ds
mv.DataBind()
End
If
End
Sub
Protected
Sub
RadAjaxManager1_AjaxRequest(sender
As
Object
, e
As
AjaxRequestEventArgs)
Dim
intpage
As
Integer
intpage = RadGrid1.CurrentPageIndex
RadGrid1.Rebind()
RadGrid1.CurrentPageIndex = intpage
LoadMessage()
End
Sub
End
Class