User control problem

T

tshad

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.RowSelectorColumn" %>
<%@ 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.RowSelectorColumn" %>

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
 
M

Martin Dechev

Hi,

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
 
T

tshad

Martin Dechev said:
Hi,



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.RowSelectorColumn" %>
<%@ 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.RowSelectorColumn" %>
<%@ 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top