Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Apply Filter 1

Status
Not open for further replies.

dorandoran

Programmer
Oct 11, 2004
48
US
I have a applyfilter that works with another page(using this sample can similar be implemented with following datasource (following datasource is for child gridview). I have a label where user will input a value for filter. i like to take that value and implement it with the code i posted so that the childgrid now have filtered data. hope it makes sense. (see example here: ) please suggest.


private DataTable ChildDataSource(string strlpID, string strSort)
{
SqlConnection conn;
SqlDataAdapter daProducts;
DataTable dsProducts;
string strQRY = "";
conn = new SqlConnection(@"Server=riverstone; Integrated Security=SSPI; Database=nw");
strQRY = "SELECT [Orders].[CustomerID],[Orders].[OrderID]," +
"[Orders].[ShipAddress],[Orders].[Freight],[Orders].[ShipName] FROM [Orders]" +
" WHERE [Orders].[CustomerID] = '" + strlpID + "'" +
"UNION ALL " +
"SELECT '" + strlpID + "','','','','' FROM [Orders] WHERE [Orders].[CustomerID] = '" + strlpID + "'" +
"HAVING COUNT(*)=0 " + strSort;
daProducts = new SqlDataAdapter(strQRY, conn);
dsProducts = new DataTable();
daProducts.Fill(dsProducts);
return dsProducts;
}
 
you have to supply more code. 1 liners do not provide any value.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
<asp:DropDownList ID="ddlQty2" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlQty2_SelectedIndexChanged">
<asp:ListItem Text="" Value="1" />
<asp:ListItem Text="30" Value="30" />
<asp:ListItem Text="60" Value="60" />
<asp:ListItem Text="90" Value="90" />
</asp:DropDownList>

and I have this on ispostback
ddlQty2.SelectedIndex = 0;
 
I took out this <asp:ListItem Text="" Value="1" />
and the filter works as expected.. hmm...
 
I think I see the problem. the autopostback only fires when the selection changes. by setting the selected index to 0 it will only fire if option 1-3 are selected (because 0 is already selected and no change would occur).

do you fetch the data in the page load event? or only the selected index changed event? if it's only the selected index changed then the page will not post back until an option other than "" is selected.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
I very much followed this link ( plus trying to implement the filter.


==== child grid =====
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
........................
//Find Child GridView control
GridView gv = new GridView();
gv = (GridView)row.FindControl("GridView2");
//Check if any additional conditions (Paging, Sorting, Editing, etc)
//to be applied on child GridView
if (gv.UniqueID == gvUniqueID)
{
gv.PageIndex = gvNewPageIndex;
gv.EditIndex = gvEditIndex;
//Check if Sorting used
if (gvSortExpr != string.Empty)
{
GetSortDirection();
strSort = " ORDER BY " + string.Format("{0} {1}", gvSortExpr, gvSortDir);
}
//Expand the Child grid
ClientScript.RegisterStartupScript(GetType(), "Expand",
"<script language="javascript"></script>");
}
..........................
}
 
okay. finally the filter is working. However, still minor glitch.
1. I select the filter item from the DDL
2. I then have to reselect my category from category DDL
3. Then my grid is populated according to the filter ddl
4. whenever I change the filter ddl then I have to reselect my category to view parent grid , then click on the + to see child grid.

Too much clicking.

My goal is to user to select filter item from ddl and see the child grid being filter right away with additional clicks.
 
I added this

protected void ddlqty2_indexchanged(ob s, ev e)
{
fillsubcategories();
}

Now I dont have reselect a category in order for filter to kick in. But say I am in the product view mode, I see all the product (master, detail type view, master being category, detail being products). I dont want to navigate away from product view , rather i like to have the same view with filtered....

i will keep on posting my progress...
 
4. whenever I change the filter ddl then I have to reselect my category to view parent grid , then click on the + to see child grid.
nested grid views can create a problem if events are not wired correctly. This introduces another variable into the problem.

The complexity of this problem is increasing as new elements in the equation are introduced. It may be best to step and back return to basics.

1. start with 1 datatable, 1 select statement and 1 gridview. get this working.
2. introduce filtering the gridview.
3. once that is working introduce the nested grid.
4. then introduce the sorting.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
just because you want the information to display within a single webpage does not mean you need all the code/markup in one page. (not to mention the preformance hit). You can break up the code across multiple objects (that you create) and markup across master/user controls/handlers/webforms.

using client scripting (jquery, prototype, dojo, mootools, etcs) you can use ajax to tie these resources together. now each set of objects has fewer responsibilities, which means less complexity for each object. the client scripting increases in complexity (because it's introduced) but it too only have 1 purpose. Load the result for a URI request into the DOM.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
GREAT Jason,

You have read my mind and excellent suggession. I will certainly follow mentioned steps, however I am under the time crunch for this phase.

The filter is working great now. User will just have to click on the + button once they set their desire filter.

Again, THANK YOU VERY VERY MUCH for your help, time, suggessions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top