-
مشكل با DataGrid
سلام
من مي خوام روي DataGrid م خاصيت Sorting رو بزارم+ اينكه مي خوام ستونهاي ديتا گريد رو خودم تعيين كنم و هدر ستونهارو هم همينطور و ديتاگريد رو در قالب يك جدول نشون بدم با تگ <table>
بخاطر اين مي خوام اينكار رو بكنم چون مي خوام كه روي ستونهاي جدول شرط بزارم مثلاً اگه مقدار اين ستون يك چيز بود يك تصوير نشون بده اگه يك چيزه ديگه بود كه تصويره دگه ومهمتر اينكه مي خوام يك ستون به جدول اضافه كنم و در اون چكباكس قرار بدم(مثل چكباكس هايي كه درInbox ميل ياهو داريم )
ميشه منو راهنمايي كنيد.
من خودم اومدم ديتاگريد رو با تگ table نشون بدم ازم اين خطا رو گرفت:
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30456: 'DataItem' is not a member of 'System.Web.UI.Control'.
Source Error:
Line 63: </tr>
Line 64: <tr>
Line 65: <td><%#Container.DataItem("nid")%></td>
Line 66: <td><%#Container.DataItem("createdate")%></td>
Line 67: <td><%#Container.DataItem("typename")%></td>
Source File: G:\aspDotNet\Source Code for Pages in Book\fordabirkhane\SortDAtaView2.aspx Line: 65
اينم از كد برنامه م:
کد:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<Script Runat="Server">
Dim dvwProducts As DataView
Sub Page_Load
Dim conNorthwind As SqlConnection
Dim dadProducts As SqlDataAdapter
Dim dstProducts As DataSet
' Create Products DataSet
dstProducts = New DataSet()
conNorthwind = New SqlConnection( "Server=localhost;UID=sa;PWD=sa;Database=dabirkhane" )
dadProducts = New SqlDataAdapter( "Select * From namevorodi", conNorthwind )
dadProducts.Fill( dstProducts, "namevorodi" )
' Create default DataView
dvwProducts = dstProducts.Tables( "namevorodi" ).DefaultView()
' Bind to datagrid
dgrdProducts.DataSource = dstProducts
dgrdProducts.DataBind()
End Sub
Sub dgrdProducts_SortCommand( s As Object, e As DataGridSortCommandEventArgs )
' Sort DataView
dvwProducts.Sort = e.SortExpression
' Rebind to DataGrid
dgrdProducts.DataSource = dvwProducts
dgrdProducts.DataBind()
End Sub
</Script>
<html>
<head><title>SortDataView.aspx</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
<form Runat="Server">
<asp:DataGrid
ID="dgrdProducts"
AutoGenerateColumns="false"
AllowSorting="True"
ShowHeader="false"
OnSortCommand="dgrdProducts_SortCommand"
Runat="Server" />
<columns>
<asp:TemplateColumn>
<itemtemplate>
<table border="1" bordercolor="#00CCFF">
<tr>
<td>شماره نامه</td>
<td>تاريخ ايجاد</td>
<td>نوع نامه</td>
</tr>
<tr>
<td><%#Container.DataItem("nid")%></td>
<td><%#Container.DataItem("createdate")%></td>
<td><%#Container.DataItem("typename")%></td>
</tr>
</table>
</itemtemplate>
</asp:TemplateColumn>
</columns>
</asp:DataGrid>
</form>
</body>
</html>
-
HannibalLecter
سلام
من از ASP.NET و زبان های تحت وب زیاد سر در نمیارم اما بهت بگم که تو باید به طور دستی اطلاعات رو توی DataGrid وارد کنید .
برای مرتب کردن هم که تمام DataGrid ها خودشون این قابلیت رو دارن و همه با کلیک کردن روی Hader اون ها مرتب میشن .
[ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ]