Popup menu in datagrid

R

R. Thomas, aka Xtreme.Net

Although I have never tried before, I'd definetly like to try to do that..
You can start off to make a custom datagrid and post questions here to email
to me if you have some problems..
will be glad to help :)
Regards.
R. Thomas
 
I

Igor Stavnitser

Is there any reason why that would not work?

All you need to do is have your datagrid generate custom javascript to
do transition. I am doing it my application as follows (it is not a
true popup menu but a pop-up row with a menu):

Supporting Javascript:
<script language="javascript">
var shownid;
function showobj(obj) {
if(obj==null)return;
if(obj!=null){
if(shownid==obj) return;
document.getElementById(obj).style.display =
'block';
}
if (shownid!=null)
document.getElementById(shownid).style.display
= 'none';
shownid=obj;
}

</script>


Last columns of the datagrid - CheckOutTS is the actual last field
displayed in the row:
<asp:TemplateColumn HeaderText="Check Out Date"
SortExpression="CheckOutTS">
<ItemStyle Wrap="False"></ItemStyle>
<ItemTemplate>
<%#Databinder.eval(Container.DataItem,"CheckOutTS")%>
<asp:placeHolder Runat="server"
OnDataBinding="PutActions"
ID="Placeholder1"></asp:placeHolder>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle Position="Bottom"
Mode="NumericPages"></PagerStyle>
</asp:datagrid>

Now the PutActions excerpts:
Protected Sub PutActions(ByVal sender As Object,
ByVal e As EventArgs)
'Container cell for popup row actions
Dim td As New HtmlTableCell

td.ColSpan = 6 'this number depends on how many columns you
have in your grid
Dim dti As DataGridItem = _
CType(sender.bindingcontainer, DataGridItem)
Dim plc As PlaceHolder = CType(sender, PlaceHolder)
td.VAlign = "Top"
'add actions to pop-up row:
dim lb as LinkButton

LinkButton lb = New LinkButton
lb.Text = "Action 1"
lb.CommandArgument = dbRecord("ID")
AddHandler lb.Command, AddressOf Action1Handler
td.Controls.Add(lb)

LinkButton lb = New LinkButton
lb.Text = "Action 2"
lb.CommandArgument = dbRecord("ID")
AddHandler lb.Command, AddressOf Action2Handler
td.Controls.Add(lb)
'... etc..

'add on mouseover event to row using ID column as unique key
dti.Attributes.Add("onmouseover",
"JavaScript:showobj('actions" & dbRecord("ID") & "');")
'INSERT constructed hidden ROW into DataGrid using ID column
as unique key
plc.Controls.Add(New LiteralControl("</TR><TR id='actions" &
dbRecord("ID") & "' style='Display:none'>"))
plc.Controls.Add(td)
end sub

Now if you are good with JS Menues you can do something much more
sophisticated. With this code I was able to build a cool looking
roll-over effect. I also build my action list dynamically so it is
context sensetive (depending on a row)
It would be interesting to see more posts on this topic!
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top