存储过程实现无限级分类(3)

存储过程实现无限级分类(3)

最后一步显示分类(只是一条select语句)

CREATE PROCEDURE sp_Column_List 
 AS
SELECT Column_ID, Column_Name, Parent_ID, Column_Path, Column_Depth, 
      Column_Order, Column_Intro
FROM Tb_Column
ORDER BY Column_Order
GO

接下来就是在界面呈现了 ,    显示的时候用的是DataGrid

Html代码如下:

<asp:DataGrid id="DataGrid1" runat="server" AutoGenerateColumns="False" Width="520px" DataKeyField="Column_Id">
                                
<Columns>
                                    
<asp:TemplateColumn HeaderText="分类信息">
                                        
<ItemTemplate>
                                            
<asp:Label id="lbname" runat="server"></asp:Label>
                                        
</ItemTemplate>
                                        
<EditItemTemplate>
                                            
<asp:TextBox id="tbdgname" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Column_Name")%>'>
                                            
</asp:TextBox>
                                        
</EditItemTemplate>
                                    
</asp:TemplateColumn>
                                    
<asp:TemplateColumn HeaderText="添加子节点">
                                        
<ItemTemplate>
                                            
<a href="#" onclick="Open('AddSonCate.aspx?fid=<%#DataBinder.Eval(Container.DataItem,"Column_Id")%>','son',280,80)">添加子分类</a>
                                        
</ItemTemplate>
                                    
</asp:TemplateColumn>
                                    
<asp:TemplateColumn HeaderText="编辑">
                                        
<ItemTemplate>
                                            
<asp:LinkButton runat="server" Text="编辑" CommandName="Edit" CausesValidation="false"></asp:LinkButton>
                                        
</ItemTemplate>
                                        
<EditItemTemplate>
                                            
<asp:LinkButton runat="server" Text="更新" CommandName="Update" CausesValidation="False"></asp:LinkButton>&nbsp;
                                            
<asp:LinkButton runat="server" Text="取消" CommandName="Cancel" CausesValidation="false"></asp:LinkButton>

                                        
</EditItemTemplate>
                                    
</asp:TemplateColumn>
                                    
<asp:TemplateColumn HeaderText="删除">
                                        
<ItemTemplate>
                                            
<asp:LinkButton runat="server" ID="lbdelete" Text="删除" CommandName="Delete" CausesValidation="false" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"Column_Id")%>'>
                                            
</asp:LinkButton>
                                        
</ItemTemplate>
                                    
</asp:TemplateColumn>
                                
</Columns>
                            
</asp:DataGrid>

 

最关键的地方在DataGrid_ItemDataBind事件中

private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
 ListItemType.AlternatingItem)
            {
                
//得到Column_Name字段的值

                string columnName = (string)DataBinder.Eval(e.Item.DataItem,    "Column_Name");
                
string columnTemp = ""
;
                
//得到深度值Column_Depth

                int columnDepth = Int32.Parse(DataBinder.Eval(e.Item.DataItem,"Column_Depth").ToString());
                
if(columnDepth>1
)
                {
                    
for(int i = 1;i<columnDepth;i++
)
                    {
                        columnTemp 
+="&nbsp;&nbsp;&nbsp;&nbsp;"
;
                    }
                    columnTemp
+=""
;
                }
                Label lbname 
= (Label)e.Item.FindControl("lbname"
);
                lbname.Text 
= columnTemp+
columnName ;
                LinkButton lbdelete 
= (LinkButton)e.Item.FindControl("lbdelete"
);
                lbdelete.Attributes.Add(
"OnClick","JavaScript:return confirm('确实要删掉此分类吗?');"
);
            }                
        }

 

Over!

  
posted @ 2007-09-17 15:36  兴百放  阅读(926)  评论(1编辑  收藏  举报