Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing Datagrid width while using EditItemIndex

Status
Not open for further replies.

dvannoy

MIS
May 4, 2001
2,765
US
Is it possible to change the column width of a datagrid when EditItemIndex is set to 0 ????

I am using the grid for data entry...I cannot change it with property builder or using code..

Is this even possible

Thanks in advance

 
Try converting the column to a Template Column and then you should be able to set the controls as needed.

Hope everyone is having a great day!

Thanks - Jennifer
 
I am using Bound Columns..If I use Template Columns, how do you bind data to a template column or use it for data entry?

Thanks

 
Here is an example of one of mine. This is within the Columns tag just like the BoundColumn.

<asp:TemplateColumn HeaderText="Miles Driven">
<ItemTemplate>
<asp:Label id="lblMiles" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.MilesDriven") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtMiles" runat="server" Font-Size="10px" Font-Names="Arial" Width="75px" Font-Bold="True" Text='<%# DataBinder.Eval(Container, "DataItem.MilesDriven") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>

Hope this helps.

Hope everyone is having a great day!

Thanks - Jennifer
 
Thanks for your responses..I figured it out.

 
I am using this approach (shown by Jennifer above) to achieve a fixed column width because the methods shown in other threads aren't working for me.

With this approach, I am able to set the minimum width. But when the text is longer than that, the width expands. I am not able to make the text in the label control wrap.

My code is:
<asp:TemplateColumn HeaderText="TA" ItemStyle-Width=100 ItemStyle-Wrap=True SortExpression="TArea">
<ItemTemplate>
<asp:Label Width=100 id="TA" runat="server"
Text='<%# DataBinder.Eval(Container.DataItem, "TArea") %>' />
</ItemTemplate>
</asp:TemplateColumn>

Any suggestions ?

TIA
Sheila
 
I am using the following and it works for me

<ItemStyle HorizontalAlign="Center" Width="30px">

 
I tried that, dvannoy, but for some reason it doesn't seem to work for me !

I also tried the server-side code:

MyGrid.Items.Cells[8].Width = 100;

But it didn't help either :(

Is there any other setting that needs attention ?
 
Heres my code and it works for me...I did have problems at first as well.


<asp:TemplateColumn HeaderText="PE #">
<HeaderStyle Font-Size="XX-Small" Font-Names="Verdana" Font-Bold="True" HorizontalAlign="Center" Width="30px"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" Width="30px"></ItemStyle>
<ItemTemplate>

 
This is my code, and it doesn't work. Please check if I am doing something wrong.

Thanks.

<asp:DataGrid runat="server" id="myDG" BackColor="#eeeeee" Width="85%" HorizontalAlign="Center"
Font-Bold="True" Font-Name="Arial" Font-Size="9pt" AutoGenerateColumns="False" OnSortCommand="SortMyDG"
GridLines="both" AllowSorting="True" AllowPaging="True">
<HeaderStyle BackColor="#DFE4EB" ForeColor="#931644" Height="26" Font-Bold="True" HorizontalAlign="Left" />
<AlternatingItemStyle BackColor="White" />
<Columns>
<asp:TemplateColumn HeaderText="PE #">
<HeaderStyle Font-Size="XX-Small" Font-Names="Verdana" Font-Bold="True" HorizontalAlign="Center" width="30px"> </HeaderStyle>
<ItemStyle HorizontalAlign="Center" Width="30px"></ItemStyle>
<ItemTemplate>
<b><%# DataBinder.Eval(Container.DataItem, "TArea") %></b>
</ItemTemplate>
</asp:TemplateColumn >

</Columns>
</asp:DataGrid>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top