row data clickable

  • Thread starter Thread starter Ashe Sjedic
  • Start date Start date
A

Ashe Sjedic

Hi,
i'm stuck at the point where you click on the row (or button on the row, or
better yet just a link on the row)

and have it do something.

Something like msgbox("you clicked on this")

Am I supposed to use a datarepeater, a datadeleter, a gridrepeater a
viewgiredeleterRepeater

or what?
??
 
Ashe (or is that Tod?),

Personally, I prefer to use the datagrid control for any data output that is
tabular, as it provides a great deal of controllable properties. For
example, by default it uses LinButtons when you add a button column. You can
specify custom columns (called Template Columns) that hold any of the other
types of control you have in your toolbox. Commonly these would be
checkboxes, etc.

Note that it might be a bit heavy-handed to use a datagrid for very simple
lists where little or no interaction is required. A DataList or Repeater
may better suit in this case.

If you use a datagrid, then you can trap user interaction events from the
grid by using its ItemCommand event handler.

Private Sub dgOuter_ItemCommand(ByVal source As System.Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgOuter.ItemCommand
'Capture events from datagrid
Dim b As LinkButton
b = e.CommandSource
If b.Text = "Details" Then
'' <your specifics here>: code goes off to do something
me.lblMyMessageToTheUser.Text = "You clicked row: " &
me.dgOuter.SelectedIndex.ToString
End If
End Sub

This snippet assumes your grid has at least one button column, with the
displayed text of the button being "Details", and a label control (called
lblMyMessageToTheUser) somewhere else on your form.

Note though that you cannot make it directly pop up an alert (messagebox),
as the code is being executed on the cient side. However, you could have it
change the text in a label control, as I demonstrated in the above code
example.

The .NET approach does take a bit of getting used to - I think it took me
about 2 months to really stop thinking of the client-side events first.
This isn't intended as a flame - I still think of the odd occasion where a
"Classic" way of doing things would better suit the particular problem.
However, there are usually ways around it, for example adding custom
attributes that add client-side javascript behaviours. (These would fire
before the server side handlers).

While I certainly agree that the Framework approach frequently (always?)
generates more lines of code than older platforms, I have to say that the
results are a much more capable system.

It is worth persevering with!


Al
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top