最後一步顯示分類(只是一條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>
<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 +=" ";
}
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!