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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to dynamically set the column width of a table in a datalist? 1

Status
Not open for further replies.

collegian

Programmer
Jul 1, 2010
64
US
Hello All,

I just wanted to know if there is any way to dynamically set the width of a column inside a table within a datalist based on the length of the text fetched from the database.I am inserting my code.In the code below I want the width of collapsible panel to be dynamically set based on the length of the address and interest fields.Please give some suggestions.


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="knzpersonnel.aspx.cs" Inherits="personnel_knzpersonnel" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>


<html xmlns="<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
<asp:ToolkitScriptManager ID="ToolkitScriptManager_CollapsiblePanel" runat="server">
</asp:ToolkitScriptManager>


<asp:Datalist ID="Datalist_PersonnelData" runat="server" Width="60%">
<HeaderTemplate>
<table border="0" cellpadding="0" cellspacing="0" width="1600">
<tr>
<td width="400">Full Name</td>
<td width="400">Phone</td>
<td width="400">Email</td>

</tr>
</table>

</HeaderTemplate>

<ItemTemplate>

<table border="0" cellpadding="0" cellspacing="0" width="1600">
<tr>
<td width="400">
<asp:panel ID="Panel2" runat="server">
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/plus.jpg" ></asp:Image>
<%#Eval("Full Name").ToString()%>

</asp:panel>

</td>
<td width="400">
<%#Eval("Phone").ToString()%>
</td>
<td width="400">
<%#Eval("Email").ToString()%>
</td>
</tr>
<br />
<tr>
//I want to set this width dynamically based on the length of text fetched from the database
<td>
<asp:panel ID="Panel1" runat="server" BorderStyle= "Outset">
<strong>Address:</strong>
<asp:Label ID="Label_Address" runat="server" Text='<%#Eval("Address").ToString()%>'></asp:Label>
<br />
<strong>Interests:</strong>
<asp:Label ID="Label_Interests" runat="server" Text='<%#Eval("Interests").ToString()%>'></asp:Label>
<br />
<asp:HyperLink ID="HyperLink_FullDetails" runat="server" Text="Full Details" NavigateUrl=" </asp:panel>

<asp:CollapsiblePanelExtender ID="CollapsibleControl_Name" ExpandControlID="Panel2" runat="server" ImageControlID="Image1" ExpandedImage="~/images/minus.jpg" CollapsedImage="~/images/plus.jpg" ExpandDirection="Vertical" CollapseControlID="Panel2" Collapsed="true" EnableViewState="false" TargetControlID="Panel1"></asp:CollapsiblePanelExtender>
</td>
</tr>

</table>
<br />
<br />

</ItemTemplate>

</asp:Datalist>
</form>
</body>
</html>
 
You will have to use the ItemDataBound event of the Datalist and use FindControl() to find the table, then get the column you want set.
 
Thanks for the reply, but how will the assignment be dynamic? I mean after obtaining the column in the table,I will again have to set it to some value.How do I ensure that it is set, according to the length of address and interests fields?
 
You will have to first get the value if the field you want, then assign that value as a the column's length
 
Does that mean I need to assign the length in terms of number of characters which are fetched for that field?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top