Forms Data Controls :: Modifying A Listview Column?
Jan 23, 2010If I have a ListView with an itemtemplate like so:
<td> <label> </label> </td>
How can I get a column in the listview and change its properties?
If I have a ListView with an itemtemplate like so:
<td> <label> </label> </td>
How can I get a column in the listview and change its properties?
I have read all kinds of great things about the new List View (well it was new when 3.5 was introduced). But I have not figured out how to set the width of a column. I have tried setting width in Layout, Item, Alternate, but none seems to affect the width.In related question, is there any way to hide a column?
View 4 RepliesI have the following ListView:
<asp:ListView ID="ListView1" runat="server" DataKeyNames="ListItemID"
DataSourceID="SqlDataSource1">
<LayoutTemplate>
<table id="ListItemsTbl" runat="server" style="width:460px; overflow: hidden">
<tr>
<th>
<asp:LinkButton runat="server" CommandName="sort"
CommandArgument="ItemDescription" Text="Description" />
</th>
<th>
<asp:LinkButton runat="server" CommandName="sort"
CommandArgument="ItemURL" Text="Link" />
</th>
<th>
<asp:LinkButton runat="server" CommandName="sort"
CommandArgument="ItemPrice" Text="Price" />
</th>
<th>
<asp:LinkButton runat="server" CommandName="sort"
CommandArgument="ItemBoughtBy" Text="Bought By" />
</th>
</tr>
<tr id="itemPlaceholder" runat="server" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr id="row" runat="server" class='<%= Container.DataItemIndex % 2 == 0 ? "row" : "altrow" %>'>
<td style="width: 10%; overflow: scroll;"><%# Eval("ItemDescription") %></td>
<td style="width: 10%; overflow: scroll;"><%#Eval("ItemURL")%></td>
<td style="width: 10%; overflow: scroll;"><%#Eval("ItemPrice")%></td>
<td style="width: 10%; overflow: scroll;"><%#Eval("ItemBoughtBy")%></td>
</tr>
</ItemTemplate>
</asp:ListView>
but the styles have no effect on the listview which just splats itself all over the screen!
What am I doing wrong? How do I control the appearence of the listview?
I'm using following code to reorder listview columns programatically somehow it is showing incorrect behaviuor for certain scenarios. Please let me know if there is any alternative way -
[Code]....
using System;
using System.Xml.Serialization;
using System.Windows.Forms;
using System.Collections;
using System.Runtime.InteropServices;
namespace TradeDesk
{
/// <summary>
/// This class is used to save and restore the column width and order settings
/// for a ListView control. Unfortunately, there is no easy way to obtain the
/// order so a Windows message must be sent to the control. This class
/// encapsulates that functionality as well as the serialization/deserialization
/// of the settings.
/// </summary>
[Serializable]
public class ListViewSettings
{
[DllImport("user32.dll")]
static extern bool SendMessage(IntPtr hWnd, Int32 msg, Int32 wParam, ref LV_COLUMN lParam);
[StructLayoutAttribute(LayoutKind.Sequential)]
struct LV_COLUMN {
public UInt32 mask;
public Int32 fmt;
public Int32 cx;
public String pszText;
public Int32 cchTextMax;
public Int32 iSubItem;
public Int32 iImage;
public Int32 iOrder;
}
const Int32 LVM_FIRST = 0x1000;
const Int32 LVM_GETCOLUMN = LVM_FIRST + 95;
const Int32 LVM_SETCOLUMN = LVM_FIRST + 96;
const Int32 LVCF_ORDER = 0x0020;
[XmlElement("ListViewColumns", typeof(ListViewColumn))]
public ArrayList listViewCols = new ArrayList();
public ListViewSettings(ListView listView) {
try {
foreach(ColumnHeader column in listView.Columns) {
LV_COLUMN pcol = new LV_COLUMN();
pcol.mask = LVCF_ORDER;
bool ret = SendMessage(listView.Handle, LVM_GETCOLUMN, column.Index, ref pcol);
listViewCols.Add( new ListViewColumn( column.Text, column.Width, pcol.iOrder ));
}
}
catch {}
}
public void RestoreFormat(ListView listView) {
try {
listView.Hide();
for( int i=0; i<listViewCols.Count; i++ ) {
foreach( ColumnHeader column in listView.Columns ) {
if( column.Text == ((ListViewColumn)listViewCols[i]).header ) {
LV_COLUMN pcol = new LV_COLUMN();
pcol.mask = LVCF_ORDER;
pcol.iOrder = ((ListViewColumn)listViewCols[i]).order;
bool ret = SendMessage(listView.Handle, LVM_SETCOLUMN, column.Index, ref pcol);
column.Width = ((ListViewColumn)listViewCols[i]).width;
break;
}
}
}
listView.Show();
}
catch {}
}
}
[Serializable]
public struct ListViewColumn {
public string header;
public int width;
public int order;
public ListViewColumn(string colHeader, int colWidth, int colOrder) {
header = colHeader;
width = colWidth;
order = colOrder;
}
}
}
How can I access the last column in a list view whose columns are varying?
View 7 RepliesIve an page with listview.. i'm performing sorting in itemdatabound event like below:
[Code]....
and my listview looks like this:
[Code]....
I want to sort with multiple columns.
what I have to add/subtract from the following listview to change the table and column width. All my attemps like the style="width: 50%" have no effect.
[Code]....
I have a listview with following structure :
column1 column2 column3
row1 dropdownlist1 dropdownlist3 dropdownlist5
dropdownlist2 dropdownlist4 dropdownlist6
row2 dropdownlist7 dropdownlist9 dropdownlist11
dropdownlist8 dropdownlist10 dropdownlist12
Now, what i want is that , when a user select something from any dropdownlist , a fuction should be called in which I can get column and row of that dropdownlist.
I can get the dropdownlist's id in that function along with row and column of dropdownlist.
How can I make the column of ListView Control invisible. The last column's header I have put in a label control and its item are in a html img control .
View 7 Repliesusing .NET 4, SQL 2008 R2 and VS2010:
My issue is that the first row of data in my db table does not seem to be output to my ListView control when I run the page. The first item in the ListView control is the 2nd row of my db table.
If I execute the stored proc listed below in SQL Server Mgmt Studio all rows are returned to the query results window.
The ListView control is defined as follows:
[Code]....
in asp.net i want to display a list of data in one column of listview with hyperlink. All the data should should apper in tabular format.
View 2 Repliesi have a problem with ListView control,when i bind data to it, it shows the heder of it also.
i don't want to show me the hedear, what should i do?
[Code]....
I have an asp:repeater control on a form. It contains 4 columns. Based on a certain value as a result of a database read, the 4th column, needs to contain a button control else it will contain plain text. How do I this in the code-behind using VB.Net? The code that I have is below but it's not working. I've never worked with a repeater control before.
Code:
<asp:repeater id="dlAppeal" runat="server">
<HeaderTemplate>
<tr id="AppealHeader" runat="server">
<td class="tableHeaderNw" align="center" width="11%">Date</td>
<td class="tableHeaderNw" align="center" width="16%">Type</td>
<td class="tableHeaderNw" align="center" width="53%">Description</td>
<td class="tableHeaderNw" align="center" width="20%">Appellant</td>
[code]....
Here is a snapshot of my gridview with selection enabled. How can I modify this, so instead of having an extra row that says select, I could have the order numbers be selected (hence the order numbers would all be underlined)
View 6 RepliesI have a very simple sub routine which I call from RowDataBind that adds a sort arrow image to the cell if a SortExpression exists. It works great except for the problem that if the gridview renders a wide table, the header text wraps and the image appears on a different line to the text. Therefore, I need to modify my subroutine so that if the header text is only one word in length, then a white-space:nowrap rule is placed on the header cell of that column.Sound really easy, but I just cannot get it to work. For some reason the white-space:nowrap rule is being added to EVERY header cell, regardless of the text inside it.
[Code]....
I have a gridview of the following form below
ID Expirydate
A 1/02/2011
B 2/02/2009
C 3/01/2009
and I would like to modify my sort expression so that when the expirydate header is clicked on, it will make all those id that has expired pop to the top . In this case, we will have the following as the results
ID Expirydate
B 2/02/2009
C 3/01/2009
A 1/02/2011
I have a gridview that has allowPaging and AllowSorting set to true. It is bound to a sqldatasource with the selectCommand firing a sql query. The sqldatasource has EnableCaching = true, and caching duration = "60". The idea is to run the paging, sorting, etc from the cache.
A separate dataUpdate event updates the data that is being loaded in the grid view, but I am not able to see the change in the gridview data till 30 seconds (caching duration) .
What is the best way to force refresh the gridview data by the dataUpdate event?
I came across this artice that tells to use CacheKeyDependency, but when I implemented it, the gridview gets refreshed at every dataUpdate event, but also the paging and sorting fires the sqldatasource Selectcommand sql query. I want this query to be fired only on dataUpdate.
i need to get data-bound items from outer listview to display in inner Listview, in this scenario:
[code]....
Where the higlighted text mean the title for outer datasource.
I am simply trying to change the listView template based on a value in the listview data. I do have this displaying the information correctly. Except when I try to change the item template based on a value in the listview. My code is below ....
View 6 RepliesI have a ListView, I've setup to use an ObjectDataSource, I've created my Layout and Item templates, and I'm able pull and view a list of my data no problem. However I want to add delete capabilities to my
ListView and my reference material tells me to go into the "Configure ListView..." option under the ListView's smart tag, the only problem is I don't have that option, the only three options in my smart tag are "Choose DataSource", "Configure DataSource..." and "Refresh Schema", what am I doing wrong?
I have anested ListView control. I also implemented a jQuery to automatically expand the TextBox control inside of the nested ListView Insert Template. The problem is, when the Textbox expand, the outer ListView control is not; therefore, the Textbox control expands underneath the buttons of the outer listView control. How do I expand the outer ListView control as the nested ListView textbox is automatically expand? One great example is in Facebook where if I add a response comment, it'll automatically push any comments below mine down. If nested Listview control is not the best way to do this, what are my options?
View 8 RepliesDoes anyone have an example for how to create a Dynamically Templated Listview with prefernces page to specify which columns & column order)? Also the listview would also have Edit, delete and insert options if possible. And uses the n-tier approach with Bus Layer and does NOT use LINQ.
View 1 RepliesIs there any way to enable alternative ListView (LV2) or any other control in case when ListView (LV1) returns no records from DB? I already have emptydatatamplate designed for this case, but I need to enable a new ListView below in this particular case and I don't know how to achieve this!
View 2 RepliesI try to datbind a listview which is inside another listview InsertItemTemplate.
[Code]....
I'm binding the listivew in the parent listview onitemcreated events. I receive the error Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
I am having trouble finding how to solve the following issue :
I am using nested listviews to display Sales and Sales details.
The main ListView displays General Information about Sales and the child ListView displays the detailed information about one sale. the child listview is shown only when the user clicks on a link (see included code, DataBind is made on PageLoad) :
ASPX Markup Code :
[Code]....
C# Behind Code :
[Code]....
If I removed the datapager part, I can manage show/hide the child list view on the button click event. but if I want to use the DataPager with the PreRender event handling, the child listview is not longer shown on button click.