G
Greg P.
I've been looking at this for a while trying to figure out how to change the
column size of a GridView. From my understanding I should be able to set
this property in design time by editing the columns and setting the
itemStyle.width property. When I do this I do not see any changes? The only
way I've been able to work around this is to covert the column into a
templateColumn and edit the width of the label that is generated, which seems
like a hack.
Any ideas why the itemStyle property deosn't seem to be asserting itself?
(look at the "notes" column in the code below)
<aspanel ID="Panel1" runat="server" Height="159px" ScrollBars="Auto"
Width="642px">
<asp:GridView ID="vwEmployee" runat="server" AllowPaging="True"
AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="EmployeeID"
DataSourceID="dsEmployee" OnRowCreated="vwEmployee_RowCreated">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Button4" runat="server"
CommandName="Select" Text="Select" Width="61px" /><br />
<asp:Button ID="Button2" runat="server"
CommandName="Update" Text="Update" /><br />
<asp:Button ID="Button3" runat="server"
CommandName="Delete" Text="Delete" Width="60px" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="EmployeeID"
SortExpression="EmployeeID" Visible="False">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Eval("EmployeeID") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label14" runat="server" Text='<%#
Bind("EmployeeID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="LastName"
SortExpression="Last Name">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%#
Bind("LastName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%#
Bind("LastName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="FirstName"
SortExpression="First Name">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%#
Bind("FirstName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%#
Bind("FirstName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Position"
SortExpression="Title">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%#
Bind("Title") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%#
Bind("Title") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Title">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%#
Bind("TitleOfCourtesy") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%#
Bind("TitleOfCourtesy") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address"
SortExpression="Address">
<EditItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Text='<%#
Bind("Address") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%#
Bind("Address") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="City" SortExpression="City">
<EditItemTemplate>
<asp:TextBox ID="TextBox7" runat="server" Text='<%#
Bind("City") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%#
Bind("City") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Region"
SortExpression="Region">
<EditItemTemplate>
<asp:TextBox ID="TextBox8" runat="server" Text='<%#
Bind("Region") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%#
Bind("Region") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Zip"
SortExpression="PostalCode">
<EditItemTemplate>
<asp:TextBox ID="TextBox9" runat="server" Text='<%#
Bind("PostalCode") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%#
Bind("PostalCode") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Country"
SortExpression="Country">
<EditItemTemplate>
<asp:TextBox ID="TextBox10" runat="server" Text='<%#
Bind("Country") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label10" runat="server" Text='<%#
Bind("Country") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Phone"
SortExpression="HomePhone">
<EditItemTemplate>
<asp:TextBox ID="TextBox11" runat="server" Text='<%#
Bind("HomePhone") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label11" runat="server" Text='<%#
Bind("HomePhone") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Extension"
SortExpression="Extension">
<EditItemTemplate>
<asp:TextBox ID="TextBox12" runat="server" Text='<%#
Bind("Extension") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label12" runat="server" Text='<%#
Bind("Extension") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Notes" ItemStyle-Width="200px">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("Notes") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("Notes") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle Width="300px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="ReportsTo"
SortExpression="ReportsTo">
<EditItemTemplate>
<asp:TextBox ID="TextBox13" runat="server" Text='<%#
Bind("ReportsTo") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label13" runat="server" Text='<%#
Bind("ReportsTo") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</aspanel>
Thanks,
Greg
column size of a GridView. From my understanding I should be able to set
this property in design time by editing the columns and setting the
itemStyle.width property. When I do this I do not see any changes? The only
way I've been able to work around this is to covert the column into a
templateColumn and edit the width of the label that is generated, which seems
like a hack.
Any ideas why the itemStyle property deosn't seem to be asserting itself?
(look at the "notes" column in the code below)
<aspanel ID="Panel1" runat="server" Height="159px" ScrollBars="Auto"
Width="642px">
<asp:GridView ID="vwEmployee" runat="server" AllowPaging="True"
AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="EmployeeID"
DataSourceID="dsEmployee" OnRowCreated="vwEmployee_RowCreated">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Button4" runat="server"
CommandName="Select" Text="Select" Width="61px" /><br />
<asp:Button ID="Button2" runat="server"
CommandName="Update" Text="Update" /><br />
<asp:Button ID="Button3" runat="server"
CommandName="Delete" Text="Delete" Width="60px" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="EmployeeID"
SortExpression="EmployeeID" Visible="False">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Eval("EmployeeID") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label14" runat="server" Text='<%#
Bind("EmployeeID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="LastName"
SortExpression="Last Name">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%#
Bind("LastName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%#
Bind("LastName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="FirstName"
SortExpression="First Name">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%#
Bind("FirstName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%#
Bind("FirstName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Position"
SortExpression="Title">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%#
Bind("Title") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%#
Bind("Title") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Title">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%#
Bind("TitleOfCourtesy") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%#
Bind("TitleOfCourtesy") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address"
SortExpression="Address">
<EditItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Text='<%#
Bind("Address") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%#
Bind("Address") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="City" SortExpression="City">
<EditItemTemplate>
<asp:TextBox ID="TextBox7" runat="server" Text='<%#
Bind("City") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%#
Bind("City") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Region"
SortExpression="Region">
<EditItemTemplate>
<asp:TextBox ID="TextBox8" runat="server" Text='<%#
Bind("Region") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%#
Bind("Region") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Zip"
SortExpression="PostalCode">
<EditItemTemplate>
<asp:TextBox ID="TextBox9" runat="server" Text='<%#
Bind("PostalCode") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%#
Bind("PostalCode") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Country"
SortExpression="Country">
<EditItemTemplate>
<asp:TextBox ID="TextBox10" runat="server" Text='<%#
Bind("Country") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label10" runat="server" Text='<%#
Bind("Country") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Phone"
SortExpression="HomePhone">
<EditItemTemplate>
<asp:TextBox ID="TextBox11" runat="server" Text='<%#
Bind("HomePhone") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label11" runat="server" Text='<%#
Bind("HomePhone") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Extension"
SortExpression="Extension">
<EditItemTemplate>
<asp:TextBox ID="TextBox12" runat="server" Text='<%#
Bind("Extension") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label12" runat="server" Text='<%#
Bind("Extension") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Notes" ItemStyle-Width="200px">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("Notes") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("Notes") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle Width="300px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="ReportsTo"
SortExpression="ReportsTo">
<EditItemTemplate>
<asp:TextBox ID="TextBox13" runat="server" Text='<%#
Bind("ReportsTo") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label13" runat="server" Text='<%#
Bind("ReportsTo") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</aspanel>
Thanks,
Greg