I have a control that I have created to display the details of a customer.
I intend the control to display differently based on a "DisplayMode" attribute set for the control.
I am using this conrol from within a datagrid three times.
Only one will **************** at once depending on whether the datagrid is in the item, edit or footer template.
The problem is the code to effect the display mode does not get executed.(setDisplay();).
I know the other code in the item pageload event is executes because the control correctly sets the sutomer name in the literal control.
Can anyone see what I am doing wrong here?
Another interesting thing is that if I try to set the Literal control value in the code behind it does not work
eg. LTCompanyName.Text = this.Attributes["CompanyName"];
But setting a variable to this value and then binding the variable to the control as I have done below does work.
Any help / suggestions would greatly appreciated.
The code for the datagrid column is:
Code:
<asp:TemplateColumn SortExpression="CompanyName ASC" HeaderText="Company">
<ItemStyle VerticalAlign="Top" HorizontalAlign="Left"></ItemStyle>
<ItemTemplate>
<uc1:Customer id="CustomerItem" DisplayMode="0" CompanyName='<%# DataBinder.Eval(Container.DataItem,"CompanyName")%>' CustomerID='<%# DataBinder.Eval(Container.DataItem,"CustomerID")%>' runat="server"/>
</ItemTemplate>
<EditItemTemplate>
<uc1:Customer id="CustomerEdit" DisplayMode="1" CompanyName='<%# DataBinder.Eval(Container.DataItem,"CompanyName")%>' CustomerID='<%# DataBinder.Eval(Container.DataItem,"CustomerID")%>' runat="server"/>
</EditItemTemplate>
<FooterTemplate>
<uc1:Customer id="CustomerAdd" DisplayMode="2" CompanyName='<%# DataBinder.Eval(Container.DataItem,"CompanyName")%>' CustomerID='<%# DataBinder.Eval(Container.DataItem,"CustomerID")%>' runat="server"/>
</FooterTemplate>
</asp:TemplateColumn>
The html code for the control is
Code:
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class='DGItemMainInfo'>
<asp:Literal id="LTCompanyName" text='<%# CompanyName%>' runat="server">
</asp:Literal>
</td>
</tr>
<tr>
<td>
<div id='CustomerID_<%# CustomerID%>' style="visibility:hidden;display:none">
<asp:Panel id="PNLItem" runat="server">Item Panel</asp:Panel>
</div>
<asp:Panel id="PNLEdit" runat="server">Edit Panel</asp:Panel>
<asp:Panel id="PNLAdd" runat="server">Add Panel</asp:Panel>
</td>
</tr>
</table>
And the code behind is:
Code:
private void Page_Load(object sender, System.EventArgs e)
{
// Put code to initialize the page here
CompanyName = this.Attributes["CompanyName"];
CustomerID = this.Attributes["CustomerID"];
displayMode = (DisplayMode) int.Parse(this.Attributes["DisplayMode"]);
setDisplay();
}
private void setDisplay()
{
PNLItem.Visible = false;
PNLEdit.Visible = false;
PNLAdd.Visible = false;
switch(displayMode)
{
case DisplayMode.Item:
PNLItem.Visible = true;
break;
case DisplayMode.Edit:
PNLEdit.Visible = true;
break;
case DisplayMode.Add:
PNLAdd.Visible = true;
break;
}
}
======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================