Click here to Skip to main content
15,914,642 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In the following code for datalist I am unable to restrict the width of the label1
used for "item_desc" from a table. I made the width and height to 33 but no effect.
The retrived data is displayed in a single line. Can anyone guide me?

XML
<head runat="server">
    <title></title>
    <style type="text/css">
        #form1 {
            height: 466px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h1>
    Datalist testing
    </h1>

    </div>
    <div id="content">
    <div class="item content">
    <br />
    <asp:DataList ID="Datalist1" runat="server" DataKeyField="item_code" RepeatDirection="Horizontal"
    RepeatLayout="Table"
    datasourceid="sqldatasource1">
    <HeaderTemplate>
    </HeaderTemplate>
    <ItemTemplate>
    Item code:
    <asp:Label Id="Itmcodelbl" runat="server" Text='<%#Eval("item_code") %>'>
    </asp:Label>
    <br />
    Item Name:
    <asp:Label Id="Itmnamelbl" runat="server" Text='<%#Eval("item_name") %>'>
    </asp:Label>
    <br />


<table Width="33"  >
<tr>
<td  Width="33" Height="33" >
Particulars:
<asp:Label Id="Label1" runat="server" Text='<%#Eval("item_desc") %>'
Width="33" Height="33">
</asp:Label>
</td>
</tr>
</table>
<br />
    <br />
    </ItemTemplate>
    </asp:DataList>
    <asp:SqlDataSource ID="sqldatasource1" runat="server"
     ConnectionString="<%$Connectionstrings:prassidhiConnectionString  %>"
     SelectCommand="SELECT [item_code], [item_name],[item_desc] FROM [item] ">
     </asp:SqlDataSource>
     <br />
     <div id="footer">
     <p class="left">
     All content copyright..
     </p>
     </div>
    </div>
    </div>
    </form>
</body>
Posted

1 solution

Hi,
add below event to your datalist
C#
private void Datalist1_ItemCreated(Object s, DataListItemEventArgs e)
{
	if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
	{
		e.Item.Width = Unit.Parse("50%");
	}
}

here you can set width property for your required item
 
Share this answer
 
Comments
S.Rajendran from Coimbatore 20-Sep-13 3:45am    
Here my item is Label1. How to mention in the above code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900