क्या डेटासोर्स खाली होने पर भी एक FooterTemplate (एक ग्रिड व्यू में) बनाने के लिए एक छोटा रास्ता है?हमेशा पाद लेख टेम्पलेट दिखाएं, यहां तक कि कोई डेटा नहीं
उत्तर
यदि आप सामग्री के बावजूद हमेशा प्रदर्शित करना चाहते हैं, तो क्या आप के बजाय GridView
के बाहर फ़ूटर एचटीएमएल नहीं डाल सकते हैं?
यदि यह किसी कारण से कोई विकल्प नहीं है, तो आप या तो add an null row to your data source if it's empty, या subclass the GridView
& override the default behaviour कर सकते हैं।
वे एकमात्र विकल्प हैं जिनके बारे में मुझे पता है (हालांकि यह थोड़ी देर के बाद से मैंने GridView
का उपयोग किया था)।
मुझे वास्तव में एचटीएमएल के साथ ऐसा करने की परवाह नहीं है, समस्या यह है कि मैं कॉलम को ग्रिड व्यू कॉलम की चौड़ाई फिट करना चाहता हूं। मैं डेटा मौजूद होने पर कुछ संक्षेप में दिखाना चाहता हूं, और एक डालने वाला आइटम (जिसे मैंने पाद लेख में लागू किया है, मुझे पता है कि मेरा मतलब क्या है?) जब आइटम टेम्पलेट पर बटन "नया" दबाया जाता है, या हमेशा पाद लेख दिखाता है। दूसरे शब्दों में: * क्या फ़ूटर दिखाने के लिए कोई तरीका है (जब कोई डेटा नहीं)? * वास्तव में यह शून्य डेटा पंक्ति चीज़ क्या है, मुझे नहीं मिला (मैं EntityDataSource का उपयोग कर रहा हूं, मुझे लगता है कि यह अधिक जटिल या असंभव होगा)। धन्यवाद दोस्त। – Shimmy
मैं एक खाली पंक्ति का उपयोग नहीं करना चाहता, मुझे ग्रिड व्यू को उपclassing नहीं है लेकिन कोई डमी डेटा नहीं है। क्या तुमने कुछ सोचा है? – Shimmy
दूसरा लिंक जो मैंने शामिल किया है (http://mattberseth.com/blog/2007/07/how%5Fto%5Fshow%5Fheader%5Fand%5Ffooter.html) में कुछ उदाहरण कोड है जो आपको ShowFooterWhenEmpty प्रॉपर्टी के साथ ग्रिड रखने की अनुमति देता है । – Alconja
मुझे इसके साथ भी परेशानी हो रही थी। Alconja से लिंक बहुत मदद करता है (धन्यवाद Alconja) लेकिन GridView.FooterRow फिर शून्य देता है। मुझे पाद लेख से नए रिकॉर्ड डालने के लिए इसकी आवश्यकता है।
यह मेरा अंतिम समाधान है जो काम करता है। ग्रिड खाली होने पर भी आप पाद लेख से डेटा सम्मिलित कर सकते हैं।
GridViewExtended.cs (App_Code फ़ोल्डर में एक वर्ग):
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace YourNamespace
{
public class GridViewExtended : GridView
{
#region Public Properties
[Category("Behavior")]
[Themeable(true)]
[Bindable(BindableSupport.No)]
public bool ShowFooterWhenEmpty
{
get
{
if (this.ViewState["ShowFooterWhenEmpty"] == null)
{
this.ViewState["ShowFooterWhenEmpty"] = false;
}
return (bool)this.ViewState["ShowFooterWhenEmpty"];
}
set
{
this.ViewState["ShowFooterWhenEmpty"] = value;
}
}
#endregion
private GridViewRow _footerRow2;
public override GridViewRow FooterRow
{
get
{
GridViewRow f = base.FooterRow;
if (f != null)
return f;
else
return _footerRow2;
}
}
protected override int CreateChildControls(System.Collections.IEnumerable dataSource, bool dataBinding)
{
int rows = base.CreateChildControls(dataSource, dataBinding);
// no data rows created, create empty table if enabled
if (rows == 0 && (this.ShowFooterWhenEmpty))
{
// create the table
Table table = this.CreateChildTable();
DataControlField[] fields;
if (this.AutoGenerateColumns)
{
PagedDataSource source = new PagedDataSource();
source.DataSource = dataSource;
System.Collections.ICollection autoGeneratedColumns = this.CreateColumns(source, true);
fields = new DataControlField[autoGeneratedColumns.Count];
autoGeneratedColumns.CopyTo(fields, 0);
}
else
{
fields = new DataControlField[this.Columns.Count];
this.Columns.CopyTo(fields, 0);
}
if (this.ShowHeaderWhenEmpty)
{
// create a new header row
GridViewRow headerRow = base.CreateRow(-1, -1, DataControlRowType.Header, DataControlRowState.Normal);
this.InitializeRow(headerRow, fields);
// add the header row to the table
table.Rows.Add(headerRow);
}
// create the empty row
GridViewRow emptyRow = new GridViewRow(-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal);
TableCell cell = new TableCell();
cell.ColumnSpan = fields.Length;
cell.Width = Unit.Percentage(100);
// respect the precedence order if both EmptyDataTemplate
// and EmptyDataText are both supplied ...
if (this.EmptyDataTemplate != null)
{
this.EmptyDataTemplate.InstantiateIn(cell);
}
else if (!string.IsNullOrEmpty(this.EmptyDataText))
{
cell.Controls.Add(new LiteralControl(EmptyDataText));
}
emptyRow.Cells.Add(cell);
table.Rows.Add(emptyRow);
if (this.ShowFooterWhenEmpty)
{
// create footer row
_footerRow2 = base.CreateRow(-1, -1, DataControlRowType.Footer, DataControlRowState.Normal);
this.InitializeRow(_footerRow2, fields);
// add the footer to the table
table.Rows.Add(_footerRow2);
}
this.Controls.Clear();
this.Controls.Add(table);
}
return rows;
}
}
}
aspx पेज में, बस <YourPrefix:GridViewExtended
साथ
<%@ Register TagPrefix="YourPrefix" Namespace="YourNamespace" %>
जोड़ सकते हैं और <asp:GridView
की जगह उम्मीद है कि यह किसी की मदद करता है।
मैंने कोशिश की क्योंकि मेरे पास एक नया रिकॉर्ड जोड़ने के विकल्प के साथ एक पाद लेख के साथ ग्रिडव्यू था। उपयोगकर्ताओं को पाद लेख में "नया जोड़ें" बटन पर क्लिक करना होगा जिसके बाद वे एक नई पंक्ति जोड़ने के लिए नियंत्रण देखेंगे। यह कोड अपेक्षित रूप से काम नहीं करता है (आपको शायद कॉल को बेस पर बदलना होगा। कोड के साथ क्रेट चाइल्ड कंट्रोल्स और आईडी के इत्यादि सेट करें)। –
इस समाधान के साथ मेरे लिए समस्या यह है कि ग्रिड खाली होने पर रोडाटाबाउंड घटना किसी कारण से पाद लेख के लिए नहीं आग लगती है। चूंकि मुझे वहां कुछ ड्रॉपडाउन पॉप्युलेट करने की आवश्यकता है, यह एक घातक दोष है। –
यह बहुत अच्छा है! धन्यवाद! – jazzBox
जैसा कि पिछले टिप्पणीकर्ताओं में से एक के रूप में उल्लेख किया गया है, रोडाटाबाउंड घटना पाद लेख के लिए आग नहीं है। मुझे एक और कोड स्निपेट मिला जो addresses this issue है, लेकिन पाद लेख को प्रदर्शित करने के अलावा, यह स्पष्ट रूप से पंक्ति बनाता है (पंक्तिबद्ध घटना को फायर कर रहा है) और इसे बांधता है (रोडाटाबाउंड ईवेंट को फायर कर रहा है)।
मैंने उपरोक्त संदर्भित कोड को कोड कनवर्टर का उपयोग करके सी # में परिवर्तित कर दिया है और कुछ मामूली बदलाव किए हैं। मैंने अपनी टिप्पणियों को भी शामिल किया क्योंकि मैंने इसे तोड़ने के लिए कोड के माध्यम से कदम रखा था। रोक्रेटेड और रोडाटाबाउंड घटनाएं अब फायरिंग कर रही हैं और मैं पाद लेखों में ड्रॉपडाउन को पॉप्युलेट करने में सक्षम हूं।
using System.Linq;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace WebUI.Controls
{
//modified from https://stackoverflow.com/questions/3437581/show-gridview-footer-on-empty-grid
public class GridViewExtended : GridView
{
private GridViewRow _footerRow;
[DefaultValue(false), Category("Appearance"), Description("Include the footer when the table is empty")]
public bool ShowFooterWhenEmpty { get; set; }
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
public override GridViewRow FooterRow {
get {
if ((this._footerRow == null)) {
this.EnsureChildControls();
}
return this._footerRow;
}
}
protected override int CreateChildControls(System.Collections.IEnumerable dataSource, bool dataBinding)
{
//creates all the rows that would normally be created when instantiating the grid
int returnVal = base.CreateChildControls(dataSource, dataBinding);
//if no rows were created (i.e. returnVal == 0), and we need to show the footer row, then we need to create and bind the footer row.
if (returnVal == 0 && this.ShowFooterWhenEmpty) {
Table table = this.Controls.OfType<Table>().First<Table>();
DataControlField[] dcf = new DataControlField[this.Columns.Count];
this.Columns.CopyTo(dcf, 0);
//creates the footer row
this._footerRow = this.CreateRow(-1, -1, DataControlRowType.Footer, DataControlRowState.Normal, dataBinding, null, dcf, table.Rows, null);
if (!this.ShowFooter) {
_footerRow.Visible = false;
}
}
return returnVal;
}
private GridViewRow CreateRow(int rowIndex, int dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, bool dataBind, object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource)
{
GridViewRow row = this.CreateRow(rowIndex, dataSourceIndex, rowType, rowState);
GridViewRowEventArgs e = new GridViewRowEventArgs(row);
if ((rowType != DataControlRowType.Pager)) {
this.InitializeRow(row, fields);
} else {
this.InitializePager(row, fields.Length, pagedDataSource);
}
//if the row has data, sets the data item
if (dataBind) {
row.DataItem = dataItem;
}
//Raises the RowCreated event
this.OnRowCreated(e);
//adds the row to the gridview's row collection
rows.Add(row);
//explicitly binds the data item to the row, including the footer row and raises the RowDataBound event.
if (dataBind) {
row.DataBind();
this.OnRowDataBound(e);
row.DataItem = null;
}
return row;
}
}
}
- 1. पाद लेख
- 2. एचटीएमएल 5 पाद लेख टैग हमेशा नीचे
- 3. JQGrid: पाद लेख पंक्ति
- 4. जेएसएफ डेटा में एकाधिक पाद लेख पंक्ति
- 5. पाद लेख केंद्रित सहायता
- 6. सीएसएस पाद लेख
- 7. टूलटिप दिखाएं कि लेख बहुत बड़ा
- 8. wicked_pdf: पाद लेख ऊंचाई/स्टाइल
- 9. डेटाग्रिड: पाद लेख
- 10. पाद लेख में wp_enqueue_script
- 11. UITableView अनुभाग पाद लेख
- 12. सीएसएस फ़्लोटिंग पाद लेख
- 13. टम्बलर-जैसे पाद लेख
- 14. कैसे पाद लेख
- 15. हेडर और पाद लेख और फ्रीमार्कर
- 16. स्क्रॉल करने योग्य सामग्री और पाद लेख के साथ शीर्षलेख/सामग्री/पाद लेख लेआउट व्यूपोर्ट
- 17. स्क्रॉल व्यू और एंड्रॉइड में पाद लेख
- 18. शीर्षलेख और पाद लेख के साथ सूचीदृश्य
- 19. चिपचिपा पाद लेख, या इसके बजाए: सामग्री
- 20. हैडर और पाद लेख एक्सएसएल एफओ
- 21. यहां तक कि एक सूची भी?
- 22. शीर्षलेख या पाद लेख में Google Analytics?
- 23. तरल टेम्पलेट्स: यहां तक कि/पाश
- 24. एंड्रॉइड सूचीदृश्य: शीर्षलेख और पाद लेख विचार
- 25. jQuery क्लोन() ईवेंट बाइंडिंग क्लोनिंग नहीं, यहां तक कि()
- 26. मॉकिंग क्लासेस जिनमें इंटरफ़ेस नहीं है और यहां तक कि कोई वर्चुअल विधियां नहीं हैं
- 27. रेल पीडीएफ प्रोन हेडर और पाद लेख
- 28. अंतिम मुद्रित पृष्ठ पर पाद लेख
- 29. विस्तारित बैंड और कॉलम पाद लेख
- 30. क्या भूमिका = "contentinfo" हमेशा पाद लेख तत्व पर जोड़ा जाना चाहिए?
आप इसे क्यों प्राप्त करना चाहते हैं? –
कृपया नीचे दी गई टिप्पणी पर एक नज़र डालें, मैंने समझाया कि मुझे इसके लिए क्या चाहिए। – Shimmy