datagrid - שאלה פשוטה

עִנבל

New member
datagrid - שאלה פשוטה

האם קיימת האפשרות לקבוע שהעמודה הראשונה שלו תכיל מספר סידורי (מ-1 עד n בהתאם למספר הרשומות שנשלפו) , או שצריך לעשות את זה ידנית?
 

gilad g

New member
בוודאי שאפשר ../images/Emo13.gif

<%@Page language="C#" EnableViewState="False" %> <script runat="server"> void Page_Load(object sender, EventArgs e) { //Create an array (that'll be the DataSource for out DataGrid). //Instead of an array, we could've used a dataset, a dataview, or whatever
string[] x = new string[13]; for(int i=0;i<13;i++) x = "xx"; DG1.DataSource = x; DataBind(); } </script> <html> <body> <form runat="server"> <asp:Datagrid runat="server" EnableViewState="false" id="DG1" > <Columns> <asp:TemplateColumn> <ItemTemplate> <%# Container.DataSetIndex + 1%> </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:Datagrid> </form> </body> </html>

"שורת המחץ" היא השרוה עם Container.DataSetIndex
 

עִנבל

New member
רק דברים מאוד ספציפיים ../images/Emo13.gif

עוד לא מצאתי זמן לשבת ללמוד מההתחלה
 

עִנבל

New member
שאלת המשך ../images/Emo163.gif

אם אני רוצה את המספור בסדר יורד, כלומר, מ-n עד 1?
 

gilad g

New member
המממ

<%@Page language="C#" EnableViewState="False" %> <script runat="server"> void Page_Load(object sender, EventArgs e) { //Create an array (that'll be the DataSource for out DataGrid). //Instead of an array, we could've used a dataset, a dataview, or whatever string[] x = new string[13]; for(int i=0;i<13;i++) x = "xx"; /*This stores the length of the array. Alternatively, you can use DataSet.Rows.Length, to get the Number of rows in the dataset */ int len = x.Length; DG1.DataSource = x; DataBind(); } </script> <html> <body> <form runat="server"> <asp:Datagrid runat="server" EnableViewState="false" id="DG1" > <Columns> <asp:TemplateColumn> <ItemTemplate> <%# l - Container.DataSetIndex %> </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:Datagrid> </form> </body> </html>

השינויים הודגשו.
פה אנחנו נאלצים לחרוג קצת מה-DataGrid, ולעבור קצת אל ה-DataSet (או אל המערך, או אל כל DataSource אחר), כדי לקבל את המספר הכולל של הרשומות.
 

gilad g

New member
אופס ../images/Emo9.gif

<%# l - Container.DataSetIndex %>​
צ"ל
<%# len - Container.DataSetIndex %>​
 
למעלה