|
°Á Àü Å¿ÀÀÇ Àâ´ã>
¾È³çÇϼ¼¿ä. ^^;; À̹ø¿¡ »õ·Ó°Ô Å¿À»çÀÌÆ®¿¡ °Á¸¦ ¿¬ÀçÇÏ°Ô µÈ ¿£Æ½½ºÀÔ´Ï´Ù. ^^;;
°³¹ßÀÚ¶ó¸é ´©±¸³ª ¾Ë°í ÀÖ´Â À¯¸íÇÑ »çÀÌÆ®ÀÎ Å¿À»çÀÌÆ®¿¡ ¿¬À縦 ÇÏ°Ô µÇ¾î¼ »ó´çÇÑ ¿µ±¤À̶ó°í
»ý°¢Çϸç, ¸¹Àº µµ¿òÀÌ µÉ ¼ö ÀÖµµ·Ï ¿½ÉÈ÷ ³ë·ÂÇϰڽÀ´Ï´Ù. ^^;;
ListView ÄÁÆ®·Ñ Part2
¾È³çÇϼ¼¿ä. ¿£Æ½½ºÀÔ´Ï´Ù. Áö³ ¾ÆÆ¼Å¬ÀÎ ListView ÄÁÆ®·Ñ Part1¿¡ À̾î À̹ø ListView ÄÁÆ®·Ñ Part2¿¡¼´Â Part1¿¡¼ ¼³¸íµå¸®Áö ¸øÇÑ ÅÛÇø´ÀÎ, SelectedItemTemplate ÅÛÇø´, EditItemTemplate ÅÛÇø´, ±×¸®°í InsertItemTemplate ÅÛÇø´¿¡ ´ëÇÑ ¼³¸íÀ» µå¸®µµ·Ï ÇϰڽÀ´Ï´Ù.
ListView ÄÁÆ®·Ñ Part2¿¡¼ ¼³¸íÇÏ°Ô µÇ´Â À̵é ÅÛÇø´Àº ListView ÄÁÆ®·ÑÀ» ÀÌ¿ëÇÑ ¼±ÅÃ(Select), ÆíÁý(Edit), »ðÀÔ(Insert), »èÁ¦(Delete), ¾÷µ¥ÀÌÆ®(Update)µî¿¡ »ç¿ëµÇ´Â ÅÛÇø´À̸ç, ASP.NET 2.0¿¡¼ »ç¿ëÇÏ´ø GridView ÄÁÆ®·ÑÀÇ ±â´É°ú À¯»çÇÏ°Ô µ¿ÀÛÇÏ°Ô µË´Ï´Ù. À̵é ÅÛÇø´À» »ç¿ëÇϱâ À§Çؼ´Â ListView ÄÁÆ®·Ñ¿¡ ¿¬°áµÇ´Â DataSource ÄÁÆ®·Ñ·Î½á, SqlDataSource ÄÁÆ®·ÑÀ» ÀÌ¿ëÇϵµ·Ï ÇϰڽÀ´Ï´Ù.
¸ÕÀú, µµ±¸ »óÀÚÀÇ µ¥ÀÌÅÍ ÅÇ¿¡¼ SqlDataSource ÄÁÆ®·ÑÀ» À¥ ÆûÀ¸·Î µå·¡±× ¾Ø µå¶ø½Ãŵ´Ï´Ù. ±× ÈÄ¿¡ SqlDataSource ÄÁÆ®·ÑÀÇ ½º¸¶Æ® ű×ÀÇ ¸Þ´º Áß "µ¥ÀÌÅÍ ¼Ò½º ±¸¼º(Configurate Data Source...)" ¸Þ´º¸¦ ÀÌ¿ëÇÏ¿©, µ¥ÀÌÅÍ ¼Ò½º¸¦ ±¸¼ºÇϵµ·Ï ÇÕ´Ï´Ù. µ¥ÀÌÅÍ ¼Ò½º ±¸¼º ¸¶¹ý»ç âÀÌ ¾Æ·¡¿Í °°ÀÌ ³ªÅ¸³ª¸é, µ¥ÀÌÅͺ£À̽º¿¡ ¿¬°áÇÒ ¿¬°á ¹®ÀÚ¿À» Á¤ÀÇÇÕ´Ï´Ù.
"´ÙÀ½(Next)" ¹öưÀ» Ŭ¸¯Çϸé, Ãß°¡ÇÑ ¿¬°á ¹®ÀÚ¿À» ±¸¼º ÆÄÀÏ(Web.Config)¿¡ ÀúÀåÇÏ°Ú³Ä°í ¹°¾îº¸°Ô µË´Ï´Ù. üũ¹Ú½º¿¡ üũ¸¦ ÇÑ ÈÄ¿¡ "´ÙÀ½(Next)" ¹öưÀ» Ŭ¸¯ÇÏ°Ô µÇ¸é, Select ¹®À» ±¸¼ºÇÒ ¼ö Àִ âÀÌ ¶ß°Ô µË´Ï´Ù. ÀúÀÇ °æ¿ì´Â Products Å×ÀÌºí¸¸À» »ç¿ëÇÒ °ÍÀ̹ǷÎ, Products Å×À̺íÀ» ¼±ÅÃÇÑ ÈÄ, ¾Æ·¡ÀÇ ±×¸²°ú °°ÀÌ Ä÷³À» ¼±ÅÃÇÕ´Ï´Ù. ¶ÇÇÑ, "Order By..." ¹öưÀ» Ŭ¸¯ÇÏ¿©, ProductID¸¦ ³»¸²Â÷¼ø Á¤·Ä·Î º¯°æÇÕ´Ï´Ù.
"°í±Þ(Advanced...)" ¹öưÀ» Ŭ¸¯ÇÏ¿© ³ªÅ¸³ª´Â â¿¡¼, "INSERT, UPDATE ±×¸®°í DELETE ¹® µî·Ï(Generate INSERT, UPDATE and DELETE Statements)"ÀÇ Ã¼Å©¹Ú½º¸¦ üũÇÑ ÈÄ, "È®ÀÎ(OK)" ¹öưÀ» Ŭ¸¯ÇÕ´Ï´Ù.
´ÙÀ½À¸·Î´Â Äõ¸®¸¦ Å×½ºÆ®Çϴ âÀÌ ³ªÅ¸³ª°Ô µË´Ï´Ù. "Äõ¸® Å×½ºÆ®(Test Query)" ¹öưÀ» Ŭ¸¯ÇÏ¿© ȸ鿡 Ãâ·ÂÇÒ µ¥ÀÌÅ͸¦ ¸ÕÀú °Ë»öÇÑ ÈÄ, "¸¶Ä§(Finish)" ¹öưÀ» Ŭ¸¯ÇÏ¿© µ¥ÀÌÅÍ ¼Ò½º ±¸¼º ¸¶¹ý»ç¸¦ Á¾·áÇÕ´Ï´Ù.
µ¥ÀÌÅÍ ¼Ò½º ±¸¼º ¸¶¹ý»ç¸¦ ÀÌ¿ëÇÏ¿© º¯°æµÈ SqlDataSource ÄÁÆ®·ÑÀÇ ±¸¹®Àº ´ÙÀ½°ú °°°Ô µË´Ï´Ù.
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString2 %>" SelectCommand="SELECT [ProductName], [CategoryID], [QuantityPerUnit], [UnitPrice], [ProductID] FROM [Products] ORDER BY [ProductID] DESC" DeleteCommand="DELETE FROM [Products] WHERE [ProductID] = @ProductID" InsertCommand="INSERT INTO [Products] ([ProductName], [CategoryID], [QuantityPerUnit], [UnitPrice]) VALUES (@ProductName, @CategoryID, @QuantityPerUnit, @UnitPrice)" UpdateCommand="UPDATE [Products] SET [ProductName] = @ProductName, [CategoryID] = @CategoryID, [QuantityPerUnit] = @QuantityPerUnit, [UnitPrice] = @UnitPrice WHERE [ProductID] = @ProductID"> <DeleteParameters> <asp:Parameter Name="ProductID" Type="Int32" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="ProductName" Type="String" /> <asp:Parameter Name="CategoryID" Type="Int32" /> <asp:Parameter Name="QuantityPerUnit" Type="String" /> <asp:Parameter Name="UnitPrice" Type="Decimal" /> <asp:Parameter Name="ProductID" Type="Int32" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="ProductName" Type="String" /> <asp:Parameter Name="CategoryID" Type="Int32" /> <asp:Parameter Name="QuantityPerUnit" Type="String" /> <asp:Parameter Name="UnitPrice" Type="Decimal" /> </InsertParameters> </asp:SqlDataSource>
ÀÌÁ¦, µ¥ÀÌÅ͸¦ Ãâ·ÂÇϰí Ãß°¡/¼öÁ¤/»èÁ¦ÀÇ ±â´ÉÀ» Á¦°øÇÏ´Â ListView ÄÁÆ®·ÑÀ» µµ±¸ »óÀÚÀÇ µ¥ÀÌÅÍ ÅÇ¿¡¼ À¥ ÆûÀ¸·Î µå·¡±× ¾Ø µå¶øÇÑ ÈÄ, ListView ÄÁÆ®·ÑÀÇ ½º¸¶Æ® ű×ÀÇ ¸Þ´º¿¡¼ µ¥ÀÌÅÍ ¼Ò½º¸¦ À§¿¡¼ Á¤ÀÇÇÑ SqlDataSource·Î ¼±ÅÃÇÕ´Ï´Ù. ±× ÈÄ ´Ù½Ã ListView ÄÁÆ®·ÑÀÇ ½º¸¶Æ® ÅÂ±× ¸Þ´º¿¡¼ "ListView ±¸¼º(Configurate ListView...)" ¸Þ´º¸¦ ¼±ÅÃÇÏ¿© ListView ÄÁÆ®·ÑÀ» ±¸¼ºÇÏ´Â ¸¶¹ý»ç¸¦ ½ÇÇàÇÕ´Ï´Ù. ListView ÄÁÆ®·ÑÀ» ±¸¼ºÇÏ´Â ¸¶¹ý»ç âÀÌ ¶ß°Ô µÇ¸é, ¾Æ·¡ÀÇ È¸é°ú °°ÀÌ ·¹À̾ƿô°ú ½ºÅ¸ÀÏÀ» ¼±Åà ÈÄ, ¿É¼ÇÀÇ ¼öÁ¤(Editing), »ðÀÔ(Inserting), »èÁ¦(Deleting) °¡´ÉÀÇ Ã¼Å© ¹Ú½º¸¦ Ã¼Å©ÇØÁØ ÈÄ, "È®ÀÎ(OK)" ¹öưÀ» Ŭ¸¯ÇÏ¿©, ListView ÄÁÆ®·ÑÀÇ ±¸¼ºÀ» Á¾·áÇÕ´Ï´Ù.
ListView ÄÁÆ®·ÑÀ» ±¸¼ºÇÏ´Â ¸¶¹ý»ç¸¦ ÀÌ¿ëÇϸé, ÀÚµ¿ÀûÀ¸·Î ListView ÄÁÆ®·Ñ¿¡ °¢ ÅÛÇø´µéÀÌ Ãß°¡µÇ°Ô µÇ¸ç, À̹ø °Á¿¡¼ ¼³¸íÇÒ SelectedItemTemplate ÅÛÇø´, EditItemTemplate ÅÛÇø´, ±×¸®°í InsertItemTemplate ÅÛÇø´ÀÌ Ãß°¡µÈ °ÍÀ» ¾Æ·¡ÀÇ ¼Ò½º¿¡¼ È®ÀÎÇÒ ¼ö ÀÖ½À´Ï´Ù.
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="ProductID" InsertItemPosition="FirstItem"> <AlternatingItemTemplate> <tr style="background-color:#FFF8DC;"> <td> <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" /> <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" /> </td> <td> <asp:Label ID="ProductNameLabel" runat="server" Text='<%# Eval("ProductName") %>' /> </td> <td> <asp:Label ID="CategoryIDLabel" runat="server" Text='<%# Eval("CategoryID") %>' /> </td> <td> <asp:Label ID="QuantityPerUnitLabel" runat="server" Text='<%# Eval("QuantityPerUnit") %>' /> </td> <td> <asp:Label ID="UnitPriceLabel" runat="server" Text='<%# Eval("UnitPrice") %>' /> </td> <td> <asp:Label ID="ProductIDLabel" runat="server" Text='<%# Eval("ProductID") %>' /> </td> </tr> </AlternatingItemTemplate> <LayoutTemplate> <table runat="server"> <tr runat="server"> <td runat="server"> <table ID="itemPlaceholderContainer" runat="server" border="1" style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;"> <tr runat="server" style="background-color:#DCDCDC;color: #000000;"> <th runat="server"></th> <th runat="server">ProductName</th> <th runat="server">CategoryID</th> <th runat="server">QuantityPerUnit</th> <th runat="server">UnitPrice</th> <th runat="server">ProductID</th> </tr> <tr ID="itemPlaceholder" runat="server"> </tr> </table> </td> </tr> <tr runat="server"> <td runat="server" style="text-align: center;background-color: #CCCCCC;font-family: Verdana, Arial, Helvetica, sans-serif;color: #000000;"> </td> </tr> </table> </LayoutTemplate> <InsertItemTemplate> <tr style=""> <td> <asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" /> <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" /> </td> <td> <asp:TextBox ID="ProductNameTextBox" runat="server" Text='<%# Bind("ProductName") %>' /> </td> <td> <asp:TextBox ID="CategoryIDTextBox" runat="server" Text='<%# Bind("CategoryID") %>' /> </td> <td> <asp:TextBox ID="QuantityPerUnitTextBox" runat="server" Text='<%# Bind("QuantityPerUnit") %>' /> </td> <td> <asp:TextBox ID="UnitPriceTextBox" runat="server" Text='<%# Bind("UnitPrice") %>' /> </td> <td> </td> </tr> </InsertItemTemplate> <SelectedItemTemplate> <tr style="background-color:#008A8C;font-weight: bold;color: #FFFFFF;"> <td> <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" /> <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" /> </td> <td> <asp:Label ID="ProductNameLabel" runat="server" Text='<%# Eval("ProductName") %>' /> </td> <td> <asp:Label ID="CategoryIDLabel" runat="server" Text='<%# Eval("CategoryID") %>' /> </td> <td> <asp:Label ID="QuantityPerUnitLabel" runat="server" Text='<%# Eval("QuantityPerUnit") %>' /> </td> <td> <asp:Label ID="UnitPriceLabel" runat="server" Text='<%# Eval("UnitPrice") %>' /> </td> <td> <asp:Label ID="ProductIDLabel" runat="server" Text='<%# Eval("ProductID") %>' /> </td> </tr> </SelectedItemTemplate> <EmptyDataTemplate> <table runat="server" style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;"> <tr> <td>No data was returned.</td> </tr> </table> </EmptyDataTemplate> <EditItemTemplate> <tr style="background-color:#008A8C;color: #FFFFFF;"> <td> <asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" /> <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" /> </td> <td> <asp:TextBox ID="ProductNameTextBox" runat="server" Text='<%# Bind("ProductName") %>' /> </td> <td> <asp:TextBox ID="CategoryIDTextBox" runat="server" Text='<%# Bind("CategoryID") %>' /> </td> <td> <asp:TextBox ID="QuantityPerUnitTextBox" runat="server" Text='<%# Bind("QuantityPerUnit") %>' /> </td> <td> <asp:TextBox ID="UnitPriceTextBox" runat="server" Text='<%# Bind("UnitPrice") %>' /> </td> <td> <asp:Label ID="ProductIDLabel1" runat="server" Text='<%# Eval("ProductID") %>' /> </td> </tr> </EditItemTemplate> <ItemTemplate> <tr style="background-color:#DCDCDC;color: #000000;"> <td> <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" /> <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" /> </td> <td> <asp:Label ID="ProductNameLabel" runat="server" Text='<%# Eval("ProductName") %>' /> </td> <td> <asp:Label ID="CategoryIDLabel" runat="server" Text='<%# Eval("CategoryID") %>' /> </td> <td> <asp:Label ID="QuantityPerUnitLabel" runat="server" Text='<%# Eval("QuantityPerUnit") %>' /> </td> <td> <asp:Label ID="UnitPriceLabel" runat="server" Text='<%# Eval("UnitPrice") %>' /> </td> <td> <asp:Label ID="ProductIDLabel" runat="server" Text='<%# Eval("ProductID") %>' /> </td> </tr> </ItemTemplate> </asp:ListView>
ÁÖÀÇ À§ÀÇ ¼Ò½º¿¡¼ º¼ ¼ö ÀÖ´Ù½ÃÇÇ, EditItemTemplate ÅÛÇø´°ú InsertItemTemplate ÅÛÇø´¿¡¼ »ç¿ëµÇ´Â TextBox ÄÁÆ®·ÑÀÇ Text ¼Ó¼ºÀº Eval() ¸Þ¼Òµå°¡ ¾Æ´Ñ, Bind() ¸Þ¼Òµå¸¦ »ç¿ëÇϰí ÀÖ½À´Ï´Ù. ÀÌ´Â, Eval() ¸Þ¼ÒµåÀÇ °æ¿ì´Â Àбâ Àü¿ë ´Ü¹æÇâ ¹ÙÀεùÀ» Á¤ÀÇÇϱ⿡, µ¥ÀÌÅÍÀÇ Ãß°¡ ¶Ç´Â ¼öÁ¤ ½Ã¿¡´Â °ªÀ» ¹Ý¿µÇÒ ¼ö ¾ø±â ¶§¹®À̸ç, ÀÌ °æ¿ì¿¡´Â ¾ç¹æÇâ ¹ÙÀεùÀ» Á¦°øÇÏ´Â Bind() ¸Þ¼Òµå¸¦ »ç¿ëÇØ¾ß¸¸ °¡´ÉÇϱ⠶§¹®ÀÔ´Ï´Ù. (Âü°í : http://msdn2.microsoft.com/ko-kr/library/ms178366.aspx) ¶ÇÇÑ, ListView¿¡¼ µ¥ÀÌÅ͸¦ Ãß°¡ÇÒ °æ¿ì, Ãß°¡ÇÒ Ç׸ñÀÌ ³ªÅ¸³ª´Â À§Ä¡¸¦ ÁöÁ¤Çϴµ¥ »ç¿ëÇϱâ À§ÇÑ ¼Ó¼ºÀÎ InsertItemPositionÀÇ °ªÀº FirstItem, LastItem, None Áß Çϳª¸¦ ¼±ÅÃÇÒ ¼ö ÀÖÀ¸¸ç, »õ·Î Ãß°¡µÇ´Â °ªÀ» ¹Ù·Î È®ÀÎÇϱâ À§Çؼ ÀÌ ¼Ó¼ºÀÇ °ªÀ» FirstItemÀ¸·Î ÁöÁ¤ÇÏ¿´½À´Ï´Ù.
±¸¼ºµÈ ListView ÄÁÆ®·ÑÀ» ºê¶ó¿ìÀú¿¡¼ º¸¸é ¾Æ·¡ÀÇ ±×¸²°ú °°ÀÌ µ¥ÀÌÅͰ¡ Ãâ·ÂµË´Ï´Ù.
»õ·Î¿î °ªÀ» Products Å×ÀÌºí¿¡ Ãß°¡Çϱâ À§ÇØ, µ¥ÀÌÅ͸¦ ÀÔ·ÂÇÑ ÈÄ¿¡ ÁÂÃøÀÇ "Insert" ¹öưÀ» Ŭ¸¯Çϸé, ÀÔ·ÂµÈ µ¥ÀÌÅÍÀÇ °ªÀÌ È¸é¿¡ Ãâ·ÂµË´Ï´Ù.
¶ÇÇÑ, »õ·ÎÀÌ Ãß°¡µÈ °ªÀ» º¯°æÇϱâ À§ÇØ, "Edit" ¹öưÀ» Ŭ¸¯Çϸé EditItemTemplate ÅÛÇø´¿¡ Á¤ÀÇµÈ Äڵ尡 ȸ鿡 º¸ÀÌ°Ô µÇ¸ç, "Cancel" ¹öưÀ» Ŭ¸¯Çϸé ÀÌÀü ȸéÀ¸·Î, "Update" ¹öưÀ» Ŭ¸¯Çϸé, ¼öÁ¤µÈ °ªÀÌ Àû¿ëµÇ¾î ȸ鿡 Ç¥½ÃµÇ°Ô µË´Ï´Ù.
"Delete" ¹öưÀ» Ŭ¸¯Çϸé, ¸ðµÎµé ¿¹»óÇϼ̴ٽÃÇÇ ¼±ÅÃÇÑ ÇàÀÇ µ¥ÀÌÅͰ¡ »èÁ¦µË´Ï´Ù.
À̷νá ListView ÄÁÆ®·ÑÀ» ÀÌ¿ëÇÑ µ¥ÀÌÅÍÀÇ Ãß°¡, ¼öÁ¤, »èÁ¦¿¡ ´ëÇÑ ¹æ¹ýÀ» ¾Ë¾Æº¸¾Ò½À´Ï´Ù. ¿©±â¿¡¼´Â SelectedItemTemplate ÅÛÇø´¿¡ Á¤ÀÇµÈ ³»¿ëÀ» »ç¿ëÇÏ´Â ¹æ¹ý¿¡ ´ëÇØ¼ Ưº°È÷ ¼³¸íÇÏÁö´Â ¾Ê¾ÒÁö¸¸, ItemTemplate ÅÛÇø´ ¶Ç´Â, AlternatingItemTemplate ÅÛÇø´¿¡ CommandNameÀÌ "Select"ÀÎ Button ÄÁÆ®·ÑÀ» Ãß°¡ÇÑ ÈÄ Button ÄÁÆ®·ÑÀ» ´©¸£°Ô µÇ¸é, Button ÄÁÆ®·ÑÀÌ À§Ä¡ÇÑ ÇàÀÌ ¼±ÅÃµÇ°Ô µË´Ï´Ù.
ÀÌ»óÀ¸·Î, ListView ÄÁÆ®·Ñ¿¡¼ »ç¿ëµÇ´Â ÅÛÇø´¿¡ ´ëÇÑ ¼³¸íÀ» ¸¶Ä¡µµ·Ï ÇϰڽÀ´Ï´Ù. ListView ÄÁÆ®·ÑÀ» »ç¿ëÇÏ´Â ¹æ¹ý¿¡ ´ëÇØ¼ Á» ´õ ¾Ë°í ½ÍÀ¸½Å ºÐÀº MSDN(
http://msdn2.microsoft.com/ko-kr/library/system.web.ui.webcontrols.listview.aspx
)À» Âü°íÇϽñ⠹ٶø´Ï´Ù.
°Á ¸ñ·ÏÀ¸·Î..
|