iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
Hi,
When I want to realize customfilter function by using WebGrid1_CustomFilter event,I did it as the sample "Walkthrough: Applying custom filtering in WebGrid ",but finally,it make errors,the error prompt "Object reference not set to an object instance",the attachment is my sample,would please have a look,and help me to find the answer to the problem, Thank you very much!
Hi zxdluck,
I tried to replicate your issue in my local end. But unfortunately, I couldn't replicate the issue in my local end. I have made my sample to programmatically rendered. I attach the sample here. Could you check my sample and please let me know if there's any error in my sample. Look forward to hear any feedback from you so I can help you further.
Regards,Bernard
Actually, there are some error in in our walkthrough. In your sample, the issue happen because it search for CategoryName column that doesn't exists in your RootTable. Since you set table property for the filter as WebGrid1's root table, WebGrid will return error which said that WebGrid couldn't find the object. I've made you a simple sample regarding Custom Filter in WebGrid. You can look for the code in there. For references, please visit: http://www.intersoftpt.com/Support/WebGrid/KB/All/5/#permalink=Create-a-custom-filter-on-WebGrid.
Hope this helps.
Hi Bernard,
Thank you very much for your sample, and I ran it ,it executed successfully, and I know, use DataSource control it can work fine. But my doubt is that I didn't use DataSource control to bind the grid,I just use WebGrid1_InitializeLayout and WebGrid1_PrepareDataBinding above,and set the CategoryID valueList in WebGrid1_PrepareDataBinding, just see the attachement in previous topic, it cause error, so I wonder if it should use datasource control to bind the grid and valuelist,or it may cause error? the following is my code,Thank you !
protected void WebGrid1_InitializeDataSource(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e) { e.DataSource = service.GetProducts(); }
protected void WebGrid1_PrepareDataBinding(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e) { if (!IsPostBack) { WebGrid1.RetrieveStructure(); } WebGrid1.RootTable.Columns.GetNamedItem("CategoryID").UseValueListForSorting = ValueListSorting.Yes; WebValueList v1 = WebGrid1.RootTable.Columns.GetNamedItem("CategoryID").ValueList; if (!v1.IsDataCached()) { DataTable dt = service.GetCategories(); v1.DataSource = dt; } //v1.DataMember = "Categories"; v1.DataTextField = "CategoryName"; v1.DataValueField = "CategoryID"; }
protected void WebGrid1_InitializeLayout(object sender, ISNet.WebUI.WebGrid.LayoutEventArgs e) { WebGrid1.RootTable.Columns.GetNamedItem("CategoryID").UseValueListForSorting = ValueListSorting.Yes; WebValueList v1 = WebGrid1.RootTable.Columns.GetNamedItem("CategoryID").ValueList; if (!v1.IsDataCached()) { DataTable dt = service.GetCategories(); v1.DataSource = dt; } //v1.DataMember = "Categories"; v1.DataTextField = "CategoryName"; v1.DataValueField = "CategoryID";
}
protected void WebGrid1_CustomFilter(object sender, FilterEventArgs e) { WebGridFilter filter; filter = e.FilterColumns.GetNamedItem("CategoryName"); if (filter != null) e.FilterColumns.Remove(filter);
WebGridFilter oldFilter; oldFilter = e.FilterColumns.GetNamedItem("CategoryID"); if (oldFilter != null) { e.FilterColumns.Remove(oldFilter); filter = new WebGridFilter(); filter.Table = oldFilter.Table; // remember to set column member field BEFORE FilterType and FilterText filter.ColumnMember = "CategoryName"; filter.FilterType = oldFilter.FilterType; filter.FilterText = oldFilter.FilterText; e.FilterColumns.Add(filter); }
Thanks for your sample,and depending on your sample,I just know my error now,thank you very much!
Glad that you have solved your problem. If you have any further question, please don't hesitate to ask us.
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname