views:

27

answers:

2

I have a ListView with about 10 rows. I have an item template for these rows and it is working correctly. I want to have two more rows in this ListView, but these rows do not match the item template as they have one more control in the first column.

The layout of the ListView is based on an HTML table with 10 rows and 4 columns. For example, the first 8 rows have only an ASP.NET TextBox control in the first column and 2 rows have in an ASP.NET TextBox control and an ASP.NET Label control in the first column.

Is there any solution to my problem?

A: 

If you are talking about GridView, please consider the following.

Bind the Grid view with the consideration that the first column is having only one control.

Use the System.Web.UI.WebControls.GridView.RowDataBound event for inserting/editing the content of your individual cell in a selected row.

For editing 8th row (zero based index), and add a Label Control in addition to the existing control,

        if (e.Row.RowIndex == 8)
        {
            System.Web.UI.WebControls.Label label = new System.Web.UI.WebControls.Label();
            label.Text = "MyRow";
            e.Row.Cells[0].Controls.AddAt(0, label);
        }

where e indicates the EventArg in the RowDataBound event.

SaravananArumugam
A: 

Setup your template and HTML table with all the controls - include the textbox and the label for the "special" rows.

In the ItemDataBound event of the ListView, you can then test to see if you should display the extra control, and if not, it can be hidden.

Private Sub MyListView_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles MyListView.ItemDataBound
    If e.Item.ItemType = ListItemType.Item Or _
       e.Item.ItemType = ListItemType.AlternatingItem Then

        Dim MyLabel As Label = DirectCast(e.Item.FindControl("MyLabel"), Label)
        MyLabel.Visible = ShowLabel()
    End If
End Sub

In the above code ShowLabel is a function that returns True or False depending upon whether the label should be displayed or not. You should replace it with whatever logic you need to test to see if the label should be displayed.

Jason Berkan