Gridview Headers for ItemTemplate and EditTemplate

T

theWizard1

In Display mode, my gridview should display FullName and Phone, and in edit
mode it should display firstname, lastname, phone, and ext.

The gridview is working except for displaying the headers properly.

Currently in display it is showing header for FirstName, Fullname, Phone,
and Ext. It should only show FullName and Phone. The contents in the
FullName are correct, concatenated LastName and FirstName. The contents in
Phone are correct, concatenated Phone and Ext in Phone.

When in edit mode, it is displaying the headers and content correctly except
for LastName, which is shown with a header of FullName.

Can someone assist regarding how to do this.

The gridview follows:
********************************************************
<asp:GridView ID="GridViewMemberUser" runat="server"
OnSelectedIndexChanged="GridViewMembershipUser_SelectedIndexChanged"
OnRowDeleted="GridViewMembership_RowDeleted"
AllowPaging="True" AutoGenerateColumns="False"
DataKeyNames="UserName"
DataSourceID="ObjectDataSourceMembershipUser" AllowSorting="True"
CellPadding="1" Font-Size="X-Small" Width="95%"
ForeColor="#333333" GridLines="None"
BorderColor="White"
OnRowDataBound="GridViewMemberUser_RowDataBound">
<Columns>
<asp:CommandField ShowDeleteButton="True"
ShowEditButton="True" ShowSelectButton="True" />
<asp:BoundField DataField="UserName"
HeaderText="UserName" ReadOnly="True"
SortExpression="UserName"
ItemStyle-HorizontalAlign="Left" />
<asp:TemplateField
ItemStyle-HorizontalAlign="Left" HeaderText="First Name" ShowHeader="false">
<EditItemTemplate>
<asp:TextBox ID="TextBox2"
runat="Server" MaxLength="25"
Text='<%#
Bind("FirstName") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="FullName"
SortExpression=""LastName""FirstName""
ItemStyle-HorizontalAlign="Left">
<EditItemTemplate>
<asp:TextBox ID="TextBox1"
runat="server" MaxLength="25" Text='<%# Bind("LastName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="LabelLastName"
runat="server" Text='<%# Bind("LastName") %>'></asp:Label>
<asp:Label ID="LabelFirstName"
runat="server" Text='<%# Bind("FirstName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Title"
HeaderText="Title"
SortExpression="Title"
ItemStyle-HorizontalAlign="Left" />
<asp:TemplateField HeaderText="Phone"
SortExpression="Phone"

ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblPhone"
runat="server" Text='<%#
FormatPhone((string)DataBinder.Eval(Container,"DataItem.Phone")) %>'
</asp:Label>
<asp:Label ID="lblExt"
runat="server" Text='<%#
FormatExt((string)DataBinder.Eval(Container,"DataItem.Ext")) %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBoxPhone"
runat="server" MaxLength="10"
Text='<%# Bind("Phone")
%>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField
ItemStyle-HorizontalAlign="Left" HeaderText="Ext">
<EditItemTemplate>
<asp:TextBox ID="TextBoxExt"
runat="server" MaxLength="6"
Text='<%# Bind("Ext")
%>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Email"
HeaderText="Email"
SortExpression="Email"
ItemStyle-HorizontalAlign="Left" />
<asp:BoundField DataField="PasswordQuestion"
HeaderText="PasswordQuestion" ReadOnly="True"

SortExpression="PasswordQuestion" ItemStyle-HorizontalAlign="Left" />
<asp:BoundField DataField="Comment"
HeaderText="Comment"
SortExpression="Comment"
ItemStyle-HorizontalAlign="Left" />
<asp:BoundField DataField="CreationDate"
HeaderText="CreationDate" ReadOnly="True"

SortExpression="CreationDate" ItemStyle-HorizontalAlign="Left" />
<asp:CheckBoxField DataField="IsApproved"
HeaderText="IsApproved" SortExpression="IsApproved" />
<asp:BoundField DataField="LastLockoutDate"
Visible="False" HeaderText="LastLockoutDate"
ReadOnly="True"
SortExpression="LastLockoutDate"

ItemStyle-HorizontalAlign="Left" />
<asp:BoundField DataField="LastLoginDate"
HeaderText="LastLoginDate" SortExpression="LastLoginDate" Visible="False" />
<asp:CheckBoxField DataField="IsOnline"
Visible="False" HeaderText="IsOnline" ReadOnly="True"
SortExpression="IsOnline" />
<asp:CheckBoxField DataField="IsLockedOut"
HeaderText="IsLockedOut" ReadOnly="True"
SortExpression="IsLockedOut"
Visible="False" />
<asp:BoundField DataField="LastActivityDate"
HeaderText="LastActivityDate" SortExpression="LastActivityDate"
Visible="False" />
<asp:BoundField
DataField="LastPasswordChangedDate" HeaderText="LastPasswordChangedDate"
Visible="False" ReadOnly="True"
SortExpression="LastPasswordChangedDate" />
<asp:BoundField DataField="ProviderName"
HeaderText="ProviderName" ReadOnly="True"
Visible="False"
SortExpression="ProviderName" />
</Columns>
<FooterStyle BackColor="#507CD1"
ForeColor="White" Font-Bold="True" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1"
Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF"
ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1"
Font-Bold="False" ForeColor="White" HorizontalAlign="Left" />
<EditRowStyle BackColor="#C0FFC0" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:ObjectDataSource
ID="ObjectDataSourceMembershipUser" runat="server" DeleteMethod="Delete"
SelectMethod="GetMembers"
TypeName="MembershipUtilities.MembershipUserAndProfileODS"
UpdateMethod="Update"
SortParameterName="SortData"
OnInserted="ObjectDataSourceMembershipUser_Inserted">
<DeleteParameters>
<asp:parameter Name="UserName" Type="String"
/>
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="UserName" Type="String"
/>
<asp:parameter Name="original_UserName"
Type="String" />
<asp:parameter Name="email" Type="String" />
<asp:parameter Name="isLockedOut"
Type="Boolean" />
<asp:parameter Name="isApproved"
Type="Boolean" />
<asp:parameter Name="comment" Type="String" />
<asp:parameter Name="lastActivityDate"
Type="DateTime" />
<asp:parameter Name="lastLoginDate"
Type="DateTime" />
<asp:parameter Name="firstName"
Type="String" />
<asp:parameter Name="lastName" Type="String"
/>
<asp:parameter Name="title" Type="String" />
<asp:parameter Name="phone" Type="String" />
<asp:parameter Name="ext" Type="String" />
</UpdateParameters>
<SelectParameters>
<asp:parameter Name="sortData" Type="String"
/>
</SelectParameters>


**********************************************************

The phone in display mode shows phone number plus the ext, if an ext exists,
as required by my users.

I am using 2 methods in my codebehind to format this:

public string FormatPhone(string myPhone)
{
string strFormattedString;
if( myPhone == null || myPhone.ToString().Length == 0)
{ strFormattedString = ""; }
else
{
string strPhone = myPhone.ToString();
strPhone = strPhone.Replace(",", "");
strPhone = strPhone.Replace("-", "");

strFormattedString = String.Format("{0:### ###-####}",
Int64.Parse(strPhone));
}
return strFormattedString;
}
public string FormatExt(string myExt)
{
string strFormattedExt;
if (myExt == null || myExt.ToString().Length == 0)
{ strFormattedExt = ""; }
else
{
string strExt = myExt.ToString();
strExt = strExt.Replace(",", "");
strExt = strExt.Replace("-", "");

strFormattedExt = "ext." + strExt;
}
return strFormattedExt;
}

Please help.
 

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

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top