Mark Bakelaar
asked on
Bind formview to server side datatable
Dear exports,
I use a formview to display some details of a datagrid. The data is bind to labels
<asp:Label ID="Label2" runat="server"><%# Eval("ReportNumber")%></as p:Label> with a datasource defined client side.
The data is bind 1 on 1, but I need to make changes to some data before it's being bind / displayed. The filed usernames can for example contain multiple comma separated usernames of which the top 3 should be displayed under each other.
Is it possible to create a datatable server side (instead of client side) and bind this to the labels in the formview, this way I am able to create the datatable the way I need it?
Thanks in advance,
MB
I use a formview to display some details of a datagrid. The data is bind to labels
<asp:Label ID="Label2" runat="server"><%# Eval("ReportNumber")%></as
The data is bind 1 on 1, but I need to make changes to some data before it's being bind / displayed. The filed usernames can for example contain multiple comma separated usernames of which the top 3 should be displayed under each other.
Is it possible to create a datatable server side (instead of client side) and bind this to the labels in the formview, this way I am able to create the datatable the way I need it?
Thanks in advance,
MB
You can change your SQL query to only get first three users.
ASKER
Thanks CodeCruiser,
This is possible, but it's a bit more complicated. The string has the following structure username1#date1¤,username2 #date2¤,us ername3#da te3¤, etc. I have the following function which I use to split a comma separated string. Then I would need to adjust this to get out username (and preferably also date).
Regards,
MB
begin
declare @idx int
declare @slice varchar(8000)
select @idx = 1
if len(@String)<1 or @String is null return
while @idx!= 0
begin
set @idx = charindex(@Delimiter,@Stri ng)
if @idx!=0
set @slice = left(@String,@idx - 1)
else
set @slice = @String
if(len(@slice)>0)
insert into @temptable(Items) values(@slice)
set @String = right(@String,len(@String) - @idx)
if len(@String) = 0 break
end
return
This is possible, but it's a bit more complicated. The string has the following structure username1#date1¤,username2
Regards,
MB
begin
declare @idx int
declare @slice varchar(8000)
select @idx = 1
if len(@String)<1 or @String is null return
while @idx!= 0
begin
set @idx = charindex(@Delimiter,@Stri
if @idx!=0
set @slice = left(@String,@idx - 1)
else
set @slice = @String
if(len(@slice)>0)
insert into @temptable(Items) values(@slice)
set @String = right(@String,len(@String)
if len(@String) = 0 break
end
return
I'm not sure if I understood your question properly, but this is how you can create a DataTable server side.
Server Side DataTable
Server Side DataTable
Another option is to not use a SQLDataSource and use a datatable. Then you can loop through the datatable, do any processing you want, and then bind it to formview.
ASKER
Thanks again for the replies,
Creating the datatable would be my preferred solution. I however have difficulties binding the datatable to the formview.
In the ascx I use (simplified, but I can confirm this is working with a client side datasource)
<table>
<tr>
<td>
<asp:formview id="ReportsView" runat="server" datakeynames="ReportID">
<ItemTemplate>
<span class='title'>Voyage</span >
<asp:Label CssClass="info" ID="Label1" runat="server"><%# Eval("Voyage")%></asp:Labe l>
</ItemTemplate>
</asp:formview>
</td>
</tr>
</table>
In the code behind I have
Public Class AlarmReportsDetails
Inherits System.Web.UI.UserControl
Public Property ReportID() As String
Get
If ViewState("ReportID") Is Nothing Then
Return ""
End If
Return DirectCast(ViewState("Repo rtID"), String)
End Get
Set(ByVal value As String)
ViewState("ReportID") = value
End Set
End Property
Protected Overrides Sub OnPreRender(ByVal e As EventArgs)
MyBase.OnPreRender(e)
Me.AlarmReportsDataSource. SelectPara meters("Re portID").D efaultValu e = Me.ReportID
Me.DataBind()
End Sub
End Class
I created a datatable (which was correctly filled) and try to bind it to the formview using me.formview.datasource=dat atable. This however did not work.
Do you perhaps have an example where a datatable is bind to a formview and where I can see how the label or textbox values are bind client side (eval)?
Thanks in advance,
MB
Creating the datatable would be my preferred solution. I however have difficulties binding the datatable to the formview.
In the ascx I use (simplified, but I can confirm this is working with a client side datasource)
<table>
<tr>
<td>
<asp:formview id="ReportsView" runat="server" datakeynames="ReportID">
<ItemTemplate>
<span class='title'>Voyage</span
<asp:Label CssClass="info" ID="Label1" runat="server"><%# Eval("Voyage")%></asp:Labe
</ItemTemplate>
</asp:formview>
</td>
</tr>
</table>
In the code behind I have
Public Class AlarmReportsDetails
Inherits System.Web.UI.UserControl
Public Property ReportID() As String
Get
If ViewState("ReportID") Is Nothing Then
Return ""
End If
Return DirectCast(ViewState("Repo
End Get
Set(ByVal value As String)
ViewState("ReportID") = value
End Set
End Property
Protected Overrides Sub OnPreRender(ByVal e As EventArgs)
MyBase.OnPreRender(e)
Me.AlarmReportsDataSource.
Me.DataBind()
End Sub
End Class
I created a datatable (which was correctly filled) and try to bind it to the formview using me.formview.datasource=dat
Do you perhaps have an example where a datatable is bind to a formview and where I can see how the label or textbox values are bind client side (eval)?
Thanks in advance,
MB
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help,
If placed in the load event and not in a Page.IsPostBack it works.
If placed in the load event and not in a Page.IsPostBack it works.