I have an aspx page with two ascx controls. The first ascx control contains the textbox and dropdown to allow the user to select the filter parameter. The 2nd control has a gridview to display the query results. The cs file has the gridview select method to call the get data. I notice that upon initial load, the gridview select method gets called. If any of the filter controls is selected, the gridview select method is also called.
Here is the problem, after the initial load, if I click on the search button with no selected filter parameter, the gridview select method does not get called. There is no direct call to the gridview select method. It is specified in the gridview markup language as follow.
I am using modelbinding in my gridview and have the selectmethod declared in my markup aspx file.
My question, how can I get the gridview select method to get call when I click on the button with no selected filtered parameter. Yes, I would like it to do another fetch even if the user makes no selection.
Thanks for any help.
<asp:GridView ID="gvCases" runat="server"
ItemType="OFAC.FOIA.BusinessEntities.NHObjects.VW_INBOX"
DataKeyNames="FOIA_Number"
AutoGenerateColumns="false"
SelectMethod="gvCases_GetData"
OnPreRender="gvCases_PreRender"
Width="100%">
I'd love to know the real answer to this question, but what I ended up doing was to add a HiddenField on the page that the SelectMethod pulled in with a Control Value Provider and then just change the value whenever I wanted to force a refresh. In my case I used a GUID so I wouldn't have to pull back the value, convert it and increment it.
protected void ForceGridViewRefresh()
{
ForceRefresh.Value = Guid.NewGuid().ToString();
}
On my select method:
public IEnumerable<TestViewModel> GetData([Control("ForceRefresh")] Guid? forceRefresh)
{
...
}
So far, this seems to be "working".
you can use GridID.DataBind() and it would immediately call the GridID_GetData() method.
Related
The scenario:
I have some JSON data which I'm using to load stored-data into fields on my form. One of these fields is a DropDownList. The DropDownList happens to be in a child, of a child ASCX control, which I'm accessing from a parent ASPX page. When this DropDownList has its SelectedIndexChanged, it makes other fields visible on the form.
I'm using one of my functions to find this control, which is working successfully, but when setting the SelectedValue of my DropDownList control, the SelectedIndexChanged event is not firing. Meaning some fields aren't loading, resulting in some JSON data not being loaded and lost.
I have seen a suggestion of simply calling ddl_SelectedIndexChange(sender, args) function, but the page I'm calling dynamically loads hundreds of child controls depending on the current request, so was wondering if there is a way of invoking the SelectedIndexChanged event (if it exists) for a control, without having to search and manually call the ddl_SelectedIndexChanged() function. Is it possible?
DirectCast(WebUtils.ControlFinder(upMain, f.fieldClientID), DropDownList).SelectedValue = f.fieldData.ToUpper()
I hope it makes sense. Sorry if I haven't made this clear enough.
I ended up using Reflection to Invoke the properties event that I required, worked a treat.
I'm a .NET newbie, but here is my question:
I have an application that makes use of Master Pages. I have a page that has a formview on it used to input address information. In the insertitemtemplate is a usercontrol that I am referencing. This usercontrol is a dropdownlist that lists countries. The usercontrol has public properties to get and set the selected value. The usercontrol is not databound, but static. The id of the usercontrol in the user control .ascx files is "DropDownListCountry". When I reference it on the formview in the page, the ID is "fvDropDownListCountry".
When I am executing the command to save the user input of the formview, I want to get the selected value that the user has indicated of which country they have selected. For the other input areas, which are text boxes, I am able to use the code such as:
Dim street1 As String = CType(myFrmView.FindControl("fvTextBoxStreet1"), TextBox).Text
Quite obviously, this approach doesn't work for a drop down list which is inside of the user control. I can't forexample use:
Dim country As String = TryCast(myFrmView.FindControl("fvDropDownListCountry"), DropDownList).SelectedValue
I've looked all around to try to find the answer on how to get the selected value from this user control, but being new at this, haven't found it yet. I have looked at functions to recursively examine a control for child controls, but haven't been able to make this work.
Any help would be appreciated
Where are you trying to get this value? An asp.net TextBox <input type=text /> automatically maintains state but this is not true of an asp.net DropDownList <select />
If you are attempting to access the DropDownList during PageInit, that value will not have been loaded yet as ViewState is not available. You need to either access it in PageLoad or as part of the SelectedIndexChanged event on the DropDownList.
FYI: Pretty sure that you can set the SelectedIndex or SelectedValue properties during PageInit but you cannot read that value.
I have a webpage. I show records from table, lets say, students in my page. I query all the students and show them in grid. I want to use a textbox for filtering the datagridview results. For example if the user types a in the textbox the grid will show only the students who has "a" in his/her name. I want to refresh the grid at the same time while textbox is being edited.
i have set the autopostback property of textbox to true, and i refresh the grid in textbox's textchanged event.But the textchanged event fires only after the textbox loses focus. How can I make it fire after user types just one character ? thanks.
You have to use the onKeyDown event. However, I'd advise you to use ASP.NET AJAX or jQuery to load the results with Ajax.
Here is one example from asp.net: http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/AutoComplete/AutoComplete.aspx
Another one, from Code project:
http://www.codeproject.com/Articles/38803/Google-Like-Search-TextBox
You might want to show some your present code, if there is a particular method you want to go with for this. Otherwise your going to get a people telling you the way they would do it.
Does it look something like this right now?
<asp:Textbox id="myTextbox" runat="server" onChange="txtChanged" AutoPostBack="true"/>
public void txtChanged(object sender, EventArgs e)
{
//Get text from textbox
string text = ((TextBox)sender).Text;
//Do what ever it is you want to do to edit the text
text = text.ToUpper();
//Update the other textbox with this text
txtMyText2.Text = text;
}
I think the best and most clean way is to use Rad Controls, here is an example on how to do it:
http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandcombo/defaultcs.aspx?product=grid
The event TextChanged only fires when you send a request to server. If you wanna launch an event or make a function when the text inside textbox changes, use an OnKeyDown event (right with Schiavini).
You can use PicNet to do this in the Client instead of the Server for a better User experience. You can find it here http://www.picnet.com.au/resources/tablefilter/demo.htm Remember that the Gridview is rendered as a HTML table, therefore you can freely use this jQuery plugin.
Good luck!
I have a gridview that I load from a linq query.
MyGridData is a the list that's returned from the linq query and that contains a variable called MyVariable. So, in the code behind I have:
MyGrid.DataSource = MyGridData;
MyGrid.DataBind();
I then went to the aspx source and added AllowSorting = true and to the boundfield I want to enable sorting for, I added SortExpression = "MyVariable".
When the page renders, if I click on the header of the column to sort the grid, I get a yellow death screen with this message:
The GridView 'MyGrid' fired event Sorting which wasn't handled
What am I doing wrong?
Thanks.
You have to implement the handler for the Sorting-Event in the Codebehind. Sort your datasource and bind your grid again.
I have an ASP.NET page where I call this.DataBind() to bind the controls. I also have various user controls embedded. One has a drop down list, the bind statement gets called for it 2x but the sender the first time is not the drop down list.
Am I using the databind incorrectly? I use databind to get the properties of my page bound to a datasource so that I can use those properties in the declarative code.
In my DropDownList, I added if (sender == dropDownList) which solved the problem
Make sure that none of your user controls are themselves calling .DataBind()
.