469,948 Members | 2,591 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,948 developers. It's quick & easy.

User control problem

This is related to my other Hiding datalistitems problem that I can't seem
to solve.

I have tried different methods which all seem to work only partially.

I decided to try to use a User Control (which I'm sure is not done
correctly) and get errors as I try to execute it.

What I want to do is take all the data from between the ItemTemplate tags
and put a control there. The I hope to be able to hide all the user
controls in my list and only show one at a time. I am hoping that I won't
lose my invisible controls as I did using a <div> tag.

Here is the control I was trying to create:

************************************************** *******************8
<%@ Register TagPrefix="mbrsc" Namespace="MetaBuilders.WebControls"
Assembly="MetaBuilders.WebControls.RowSelectorColu mn" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web.Mail" %>

<table>
<tr>
<td>
<asp:ImageButton ID="ExpandButton" visible="false"
runat="server" Font-Size="2" ImageUrl="../images/expand.gif" Width="16"
Height="16" CommandName="Select" AlternateText="Click here to see
details"></asp:ImageButton>
<asp:ImageButton ID="CollapseButton" visible="false"
runat="server" Font-Size="2" ImageUrl="../images/collapse.gif" Width="16"
Height="16" CommandName="Select" AlternateText="Click here to see
details"></asp:ImageButton>
<asp:label id="PositionID" Visible="false" runat="server"
Text='<%# DataBinder.Eval(Container.DataItem, "PositionID") %>' />
<asp:label id="QuestionUnique" Visible="false" runat="server"
Text='<%# DataBinder.Eval(Container.DataItem, "QuestionUnique") %>' />
<asp:label id="QuestionType" Visible="false" runat="server"
Text='<%# DataBinder.Eval(Container.DataItem, "QuestionType") %>' />
</td>
<td>
<asp:label visible=false id="Question" text=<%#
DataBinder.Eval(Container.DataItem, "Question") %> runat="server" />
</td>
</tr>
<tr>
<td>
</td><br>
<td align="right">
<asp:DataGrid visible="False"
border=1
id="DataGrid1"
runat="server"
Width="400px"
AutoGenerateColumns="False"
BorderColor="#999999"
gridlines="both"
ShowFooter="false"
onItemDataBound="DataGrid1_ItemDataBound">
<AlternatingItemStyle BorderWidth="0px" BorderStyle="None"
BorderColor="White" BackColor="linen"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" BackColor="#6699cc"></HeaderStyle>
<Columns>
<asp:TemplateColumn ItemStyle-Width="15" HeaderText="">
<itemtemplate>
<asp:Label ID="SortOrder" runat="server"
Text='<%# DataBinder.Eval(Container, "DataItem.SortOrder") %>'> </asp:Label>
</itemtemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Answer">
<itemtemplate>
<asp:Label ID="lblAnswer" runat="server"
Text='<%# DataBinder.Eval(Container, "DataItem.Answer") %>'> </asp:Label>
</itemtemplate>
</asp:TemplateColumn>
<asp:TemplateColumn Visible="false">
<itemtemplate>
<asp:Label ID="lblPositionID" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.PositionID") %>'> </asp:Label>
</itemtemplate>
</asp:TemplateColumn>
<asp:TemplateColumn Visible="false">
<itemtemplate>
<asp:Label ID="lblQuestionUnique" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.QuestionUnique") %>'> </asp:Label>
</itemtemplate>
</asp:TemplateColumn>
<asp:TemplateColumn Visible="false">
<itemtemplate>
<asp:Label ID="lblAnswerUnique" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.AnswerUnique") %>'> </asp:Label>
</itemtemplate>
</asp:TemplateColumn>
<mbrsc:RowSelectorColumn allowselectall="false"
SelectionMode="Single" HeaderText="Select" AutoPostBack="false"
OnSelectionChanged="ShowSelections" ItemStyle-Width="10%"/>
</Columns>
</asp:DataGrid><br id="dataGridBr" visible="false" runat="server"
/>
<asp:button visible="false" ID="submitQuestion" runat="server"
Text="Select" OnClick="submitQuestion_click" />
</td>
</tr>
</table>
************************************************** *****************************************

At first I got an error:

Parser Error Message: Object reference not set to an instance of an object.

This was caused by my 3rd party control, so I added this line from the
original file:

<%@ Register TagPrefix="mbrsc" Namespace="MetaBuilders.WebControls"
Assembly="MetaBuilders.WebControls.RowSelectorColu mn" %>

Then I got an error:

Compiler Error Message: BC30456: 'DataItem' is not a member of
'System.Web.UI.Control'.

I added the imports from the first file:

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

But I still get that error.

What am I missing here and will this solve my problem?

Thanks,

Tom
Nov 19 '05 #1
2 2951
Hi,

"tshad" <ts**********@ftsolutions.com> wrote in message
news:O$**************@TK2MSFTNGP10.phx.gbl...
<snip>
Then I got an error:

Compiler Error Message: BC30456: 'DataItem' is not a member of
'System.Web.UI.Control'.

I added the imports from the first file:

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

But I still get that error.

What am I missing here and will this solve my problem?
eg:
DataBinder.Eval(Container.DataItem, "PositionID")

should be

DataBinder.Eval(Container, "DataItem.PositionID")

Thanks,

Tom


Hope this helps,
Martin Dechev
ASP.NET MVP

Nov 19 '05 #2
"Martin Dechev" <de*******@hotmail.com> wrote in message
news:OK*************@tk2msftngp13.phx.gbl...
Hi,

"tshad" <ts**********@ftsolutions.com> wrote in message
news:O$**************@TK2MSFTNGP10.phx.gbl...
<snip>
Then I got an error:

Compiler Error Message: BC30456: 'DataItem' is not a member of
'System.Web.UI.Control'.

I added the imports from the first file:

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

But I still get that error.

What am I missing here and will this solve my problem?


eg:
DataBinder.Eval(Container.DataItem, "PositionID")

should be

DataBinder.Eval(Container, "DataItem.PositionID")


Why is that different?

It did seem to get rid of that error. Now I am getting the following error:

Compiler Error Message: BC30456: 'DataGrid1_ItemDataBound' is not a member
of 'ASP.datalistitem_ascx'.

Source Error:

Line 21: </td><br>
Line 22: <td align="right">
Line 23: <asp:DataGrid visible="False"

With Line 23: highlighted. This codes was taken directly from the asp.net
page. I am trying to set an datalistitem that I can make visible and not
visible programmatically. But first I need to make it work as it was.

Here is the .aspx page (without the script code):
************************************************** ***************************************
<%@ Page Language="VB" trace="true" debug="true" AutoEventWireup="true"
ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<%@ Register TagPrefix="fts" TAgName="header"
src="..\includes\ApplicantHeaders.ascx" %>
<%@ Register TagPrefix="fts" TAgName="footer"
src="..\includes\staffingFooters.ascx" %>
<%@ Register TagPrefix="fts" TAgName="dataListItem" src="datalistitem.ascx"
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ Register TagPrefix="mbrsc" Namespace="MetaBuilders.WebControls"
Assembly="MetaBuilders.WebControls.RowSelectorColu mn" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web.Mail" %>
<!-- #include file="..\includes\slidemenus.inc" -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Take Screen Test</title>
<link href="staffing.css" rel="stylesheet" type="text/css">
<fts:header id=ctl1 runat="Server" />
<!-- Content Starts Here -->
<form id="Form1" runat="server">
<input type="hidden" name="__SCROLLPOS" value="" />
<center>
<br>
<table border="0" class=basicTable style="margin-left:5" >
<tr>
<th colspan="2"><asp:Label id="tableTitle" Font-Size=10
runat="server">Screen Questions and Answers</asp:Label><br>
<asp:Label id="jobTitle" Font-Size=12 runat="server"/>
</th>
</tr>
<tr>
<td>
<asp:datalist id="DataList1"
runat="server"
Width="100%"
BorderWidth="0px"
OnItemCommand="OnSelectIndexChanged"
footerstyle-horizontalalign="center"
CellPadding="0"
CellSpacing="0"
style="margin:0">
<AlternatingItemStyle cssClass=alternateRow ></AlternatingItemStyle>
<ItemTemplate>
<fts:dataListItem id=dataListItemCtl runat="Server"
/>
</ItemTemplate>
<SeparatorTemplate>
<hr visible="false" style="margin:0" runat="server" />
</SeparatorTemplate>
<FooterTemplate>
<SeparatorTemplate>
<hr style="margin:0">
</SeparatorTemplate>
<asp:Button ID="CollapseAll" visible=false text="Collapse All"
runat="server" onClick="collapseAll_click" AlternateText="Click here to see
details"></asp:Button>&nbsp;&nbsp;
<asp:Button ID="ExpandAll" visible=false text="Expand All"
runat="server" onClick="expandAll_click" AlternateText="Click here to see
details"></asp:Button>
<asp:Button ID="Submit" text=" Submit " runat="server"
onClick="submitScreenTest_click" AlternateText="Click here to see
details"></asp:Button>
</FooterTemplate>
</asp:datalist>
<asp:Label id="InfoLabel" visible="false" runat="server" Height="23px"
Width="597px" BackColor="#FFFFC0" Font-Bold="True"></asp:Label>
<font color="#FF0000">
<asp:label ID="lblErrorMessage" runat="server" />
</font>
</td>
</tr>
</table>
<asp:Label runat="server" id="Message" />
</center>
</form>

<!-- Content Ends Here -->
<fts:footer id=ctl2 runat="Server" />
************************************************** ****************************************

Here is the .ascx page:
************************************************** ****************************************
<%@ Register TagPrefix="mbrsc" Namespace="MetaBuilders.WebControls"
Assembly="MetaBuilders.WebControls.RowSelectorColu mn" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<table>
<tr>
<td>
<asp:ImageButton ID="ExpandButton" visible="false"
runat="server" Font-Size="2" ImageUrl="../images/expand.gif" Width="16"
Height="16" CommandName="Select" AlternateText="Click here to see
details"></asp:ImageButton>
<asp:ImageButton ID="CollapseButton" visible="false"
runat="server" Font-Size="2" ImageUrl="../images/collapse.gif" Width="16"
Height="16" CommandName="Select" AlternateText="Click here to see
details"></asp:ImageButton>
<asp:label id="PositionID" Visible="false" runat="server"
Text='<%# DataBinder.Eval(Container, "DataItem.PositionID") %>' />
<asp:label id="QuestionUnique" Visible="false" runat="server"
Text='<%# DataBinder.Eval(Container, "DataItem.QuestionUnique") %>' />
<asp:label id="QuestionType" Visible="false" runat="server"
Text='<%# DataBinder.Eval(Container, "DataItem.QuestionType") %>' />
</td>
<td>
<asp:label visible=false id="Question" text=<%#
DataBinder.Eval(Container, "DataItem.Question") %> runat="server" />
</td>
</tr>
<tr>
<td>
</td><br>
<td align="right">
<asp:DataGrid visible="False"
border=1
id="DataGrid1"
runat="server"
Width="400px"
AutoGenerateColumns="False"
BorderColor="#999999"
gridlines="both"
ShowFooter="false"
onItemDataBound="DataGrid1_ItemDataBound">
<AlternatingItemStyle BorderWidth="0px" BorderStyle="None"
BorderColor="White" BackColor="linen"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" BackColor="#6699cc"></HeaderStyle>
<Columns>
<asp:TemplateColumn ItemStyle-Width="15" HeaderText="">
<itemtemplate>
<asp:Label ID="SortOrder" runat="server"
Text='<%# DataBinder.Eval(Container, "DataItem.SortOrder") %>'> </asp:Label>
</itemtemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Answer">
<itemtemplate>
<asp:Label ID="lblAnswer" runat="server"
Text='<%# DataBinder.Eval(Container, "DataItem.Answer") %>'> </asp:Label>
</itemtemplate>
</asp:TemplateColumn>
<asp:TemplateColumn Visible="false">
<itemtemplate>
<asp:Label ID="lblPositionID" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.PositionID") %>'> </asp:Label>
</itemtemplate>
</asp:TemplateColumn>
<asp:TemplateColumn Visible="false">
<itemtemplate>
<asp:Label ID="lblQuestionUnique" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.QuestionUnique") %>'> </asp:Label>
</itemtemplate>
</asp:TemplateColumn>
<asp:TemplateColumn Visible="false">
<itemtemplate>
<asp:Label ID="lblAnswerUnique" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.AnswerUnique") %>'> </asp:Label>
</itemtemplate>
</asp:TemplateColumn>
<mbrsc:RowSelectorColumn allowselectall="false"
SelectionMode="Single" HeaderText="Select" AutoPostBack="false"
OnSelectionChanged="ShowSelections" ItemStyle-Width="10%"/>
</Columns>
</asp:DataGrid><br id="dataGridBr" visible="false" runat="server"
/>
<asp:button visible="false" ID="submitQuestion" runat="server"
Text="Select" OnClick="submitQuestion_click" />
</td>
</tr>
</table>
************************************************** ****************************************

I hope a user control is the way to go to solve this. I have tried a bunch
of other things that didn't work.

Thanks,

Tom.


Thanks,

Tom


Hope this helps,
Martin Dechev
ASP.NET MVP

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Sam Kuehn | last post: by
4 posts views Thread by thomson | last post: by
8 posts views Thread by David Lozzi | last post: by
5 posts views Thread by Segfahlt | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.