KoldFuzun
asked on
ASP.NET Datagrid, populating empty rows from recordset
ASP.NET newbie here. I am using a text editor to develop my application as I havent had the time to learn VS.NET yet, so this may give you an idea of how new I am.
Onto the problem at hand:
I am returning a recordset to a datagrid, but some of the rows have null values. I want to use a conditional so that if the record is empty I can return a string, namely "Untitled". Do I have to custom build my datagrid if I want to do this?
Onto the problem at hand:
I am returning a recordset to a datagrid, but some of the rows have null values. I want to use a conditional so that if the record is empty I can return a string, namely "Untitled". Do I have to custom build my datagrid if I want to do this?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
assuming the data source is either a datatable or a dataview.
ASKER
Thanks guys. This is actually a recordset from an Index Server query. I assume it is not the same, since after implementing b1xml2's code I get
Type 'DataRowView' is not defined
*extreme newbie* my apologies and thanks for the help
Type 'DataRowView' is not defined
*extreme newbie* my apologies and thanks for the help
typo
===
<ItemTemplate><%# IIf(DirectCast(Container.D ataItem,Da taViewRow) .Row.IsNul l("data"), "Untitled" ,DirectCas t(Containe r.DataItem ,DataViewR ow)("data" ).ToString ) %></ItemTemplate>
===
<ItemTemplate><%# IIf(DirectCast(Container.D
ASKER
Here's where i frustrate you :)
Same error. here is the code I am using
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>docTitle</ HeaderTemp late>
<ItemTemplate><%# IIf(DirectCast(Container.D ataItem,Da taViewRow) .Row.IsNul l("DocTitl e"),"Untit led",Direc tCast(Cont ainer.Data Item,DataV iewRow)("D ocTitle"). ToString) %></ItemTemplate>
</asp:TemplateColumn>
<asp:HyperLinkColumn HeaderText="Title" DataNavigateUrlField="VPAT H" DataNavigateUrlFormatStrin g="" DataTextField="DocTitle" Target="_blank" ItemStyle-Font-Size="11px" />
<asp:BoundColumn DataField="create" HeaderText="Created" ItemStyle-Font-Size="11px" ></asp:Bou ndColumn>
<asp:BoundColumn DataField="write" HeaderText="Modified" ItemStyle-Font-Size="11px" ></asp:Bou ndColumn>
<asp:BoundColumn DataField="characterizatio n" HeaderText="Abstract" ItemStyle-Font-Size="11px" ></asp:Bou ndColumn>
</Columns>
Same error. here is the code I am using
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>docTitle</
<ItemTemplate><%# IIf(DirectCast(Container.D
</asp:TemplateColumn>
<asp:HyperLinkColumn HeaderText="Title" DataNavigateUrlField="VPAT
<asp:BoundColumn DataField="create" HeaderText="Created" ItemStyle-Font-Size="11px"
<asp:BoundColumn DataField="write" HeaderText="Modified" ItemStyle-Font-Size="11px"
<asp:BoundColumn DataField="characterizatio
</Columns>
Whats the data source type? a datatable, or data reader??
do us a favour:
<asp:TemplateColumn>
<HeaderTemplate>docTitle</ HeaderTemp late>
<ItemTemplate><%# Container.DataItem.GetType () %></ItemTemplate>
</asp:TemplateColumn>
This will tell me the data type of the container
do us a favour:
<asp:TemplateColumn>
<HeaderTemplate>docTitle</
<ItemTemplate><%# Container.DataItem.GetType
</asp:TemplateColumn>
This will tell me the data type of the container
The ugly way is this:
<asp:TemplateColumn>
<HeaderTemplate>docTitle</ HeaderTemp late>
<ItemTemplate><%# IIf(DataBinder.Eval(Contai ner.DataIt em,"DocTit le").ToStr ing() = "" ,"Untitled",DataBinder.Eva l(Containe r.DataItem ,"DocTitle ").ToStrin g()) %></ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<HeaderTemplate>docTitle</
<ItemTemplate><%# IIf(DataBinder.Eval(Contai
</asp:TemplateColumn>
ASKER
System.Data.DataRowView ?
Mine was much simple
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent, this works very well, thank you. Oddly enough I am running into rows which still appear blank though. Any ideas?
jitganguly, i would not disagree with you, however I am such a newbie in .NET I was not able to determine how to implement your solution.
jitganguly, i would not disagree with you, however I am such a newbie in .NET I was not able to determine how to implement your solution.
in that case, there are empty string values...
<ItemTemplate><%# IIf(DirectCast(Container.D ataItem,Da taRowView) .Row.IsNul l("DocTitl e") OrElse DirectCast(Container.DataI tem,DataRo wView)("Do cTitle").T oString(). Trim() = "","Untitled",DirectCast(C ontainer.D ataItem,Da taRowView) ("DocTitle ").ToStrin g) %></ItemTemplate>
<ItemTemplate><%# IIf(DirectCast(Container.D
>>I was not able to determine how to implement your solution.
Item data bound fires just before data bound so thats the last chance you could tweak with your data. If you had used VS.net, it would have been easier for you and accpeted my comment :-)
Item data bound fires just before data bound so thats the last chance you could tweak with your data. If you had used VS.net, it would have been easier for you and accpeted my comment :-)
ASKER
Sweet, thanks b1xml2, that worked perfectly.
jitanguly, i realize that if I had more knowledge or a better understanding of the VS.NET IDE i would have known how to implement your solution, so it is primarily my problem for not being able to implement your solution.
If if it acceptable to you both I will split the points and give jitanguly 150 points for being the first to answer and providing an assisted solution that others (who arent newbs like me!) will be able to use. Is this ok?
jitanguly, i realize that if I had more knowledge or a better understanding of the VS.NET IDE i would have known how to implement your solution, so it is primarily my problem for not being able to implement your solution.
If if it acceptable to you both I will split the points and give jitanguly 150 points for being the first to answer and providing an assisted solution that others (who arent newbs like me!) will be able to use. Is this ok?
Ok
=======================
<asp:DataGrid Id="DataGrid1" runat="server" AutoGenerateColumns="False
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>Use Id</HeaderTemplate>
<ItemTemplate><%# IIf(DirectCast(Container.D
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
or
<asp:DataGrid Id="DataGrid1" runat="server" AutoGenerateColumns="False
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>Use Id</HeaderTemplate>
<ItemTemplate><%# ProcessItem(Container.Data
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
...
Public Function ProcessItem(ByVal dataItem As Object, ByVal column As String) As String
Dim viewRow As DataViewRow = DirectCast(dataItem,DataVi
Dim value As String = "Untitled"
If Not viewRow.Row.IsNull(column)
value = viewRow(column).ToString()
End If
Return value
End Function