How to create a data table w/ columns and rows

  • Thread starter Thread starter Jim
  • Start date Start date
J

Jim

My subject probably isn't very descriptive of what I want to do, so
let me explain:

I wna tto have a website that holds a number of products, grouped by
category. On the administration page of the website, I want to allow
the operator to move products between categories. The interface I
have in mind would have two dropdowns at the top, one to select the
FROM categroy, which would cause the page to re-post, and thus display
all of the products in that catgegory. The second dropdown would
allow the operator to select the TO category where products would be
placed when they clicked the "Submit" button at the bottom.

Each prodcut has a name and an image. The images are stored on the
server, and their filenames are stored along with the item
descriptions in the database. What I would like for the page to do is
to display a grid, say thrww columns wide, and in each cell, show the
image, then the product name, and then a checkbox that would indicate
that this product is to be moved. For the time being, all the items
in the category can be displayed all at once, although eventually I'll
probably limit the number of rows in the table to 10-15, and then
provide links to the previous and next pages, to keep the page load
time down.

This sounds to me like something along the lines of what you'd do with
a datagrid control, but those usually repeat records one per row. In
this case, each row would have three records on it, as I stated above.
Each cell would then show the image, and then the product name below
it, and then a checkbox below that. Any suggestions as to how I might
lay out soemthing like this? I'm a little new to all these .NET
controls. Thanks!

JIM
 
Jim,
You can get the kind of flexiblity you are looking for with creative use of the data grid. What you need to do is set up "template columns" in which each cell can contain multiple controls and you can control the layout like this:

<asp:TemplateColumn><ItemTemplate><asp:CheckBox id=CheckBox1 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.FileName") %>' Checked='<%# DataBinder.Eval(Container, "DataItem.Checked") %>'></asp:CheckBox><DIV align="right">(Pages:<asp:Label id=Label1 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Pages") %>'></asp:Label>)</DIV></ItemTemplate></asp:TemplateColumn>

When your cells need contols with Event Handlers assigned dynamically, you can use the Item_DataBound Event in your code module as: (where the <i>second</i> control in the first cell is a dropdown box)

Private Sub myDG_ItemDatabound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles dgProcedures.ItemDataBound

dim myDropDown as dropdownbox = directcast(e.item.cells(0).controls(1),dropdownbox)
addHandler myDropDown.SelectedIndexChange, addressof myDropDownHandler
'rem: the myDropDownHandler should not have a "handles" statement, but must have the same signature as the
' event hanldler

End Sub

I hope these point you in the right direction

Cos Callis, MCAD
 
Hello!

I need the same functionality as Jim, however, I don't do Visual Basic.
Can you translate that VB sample code into C#, perchance?

Thanks so much,

Google Jenny
 
Back
Top