AjaxControlToolkit DropDownExtender inside a table always displays associated panel - asp.net

I have a textarea that has the ajaxcontroltoolkit dropdownextender associated with it, and a panel that contains a gridview with the options for the user to select from.
Here is the code for these items:
<asp:UpdatePanel ID="updPnlView" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtSiteName" runat="server" TextMode="MultiLine" Rows="4" Columns="33" ReadOnly="true" /></td>
<ajaxToolkit:DropDownExtender runat="server" ID="popupdropdown"
DropDownControlID="pnlGrid" TargetControlID="txtSiteName" />
<asp:Panel runat="server" ID="pnlGrid" Style="display: none; visibility: hidden" Height="300" ScrollBars="Vertical">
<asp:GridView ID="gvSite" runat="server" AutoGenerateColumns="False" Width="100%"
DataKeyNames="ID,FullAddress" DataSourceID="odsSite" OnRowDataBound="gvSite_RowDataBound"
ShowFooter="false" ShowHeader="false" OnSelectedIndexChanged="gvSite_SelectedIndexChanged" >
<Columns>
<asp:CommandField ButtonType="Link" SelectText="Select" ShowSelectButton="true" ItemStyle-CssClass="HiddenColumn" />
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="FullAddress" runat="server" Text='<%# Eval("FullAddress").ToString().Replace("\n", "<br/>") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CheckBoxField DataField="DisabledFLG" ItemStyle-CssClass="HiddenColumn" />
</Columns>
</asp:GridView>
</asp:Panel>
<asp:ObjectDataSource ID="odsSite" runat="server" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetList"
TypeName="SOM.DCO.MOGWAI.Bll.SiteManager"
onselecting="odsSite_Selecting" SortParameterName="SortExpression"
onselected="odsSite_Selected" >
<SelectParameters>
<asp:Parameter Name="myCriteria" Type="Object" />
<asp:Parameter Name="myIDs" Type="Object" />
<asp:Parameter Name="sortExpression" Type="String" />
<asp:Parameter Name="bypassCache" Type="Boolean" />
</SelectParameters>
</asp:ObjectDataSource>
</ContentTemplate>
</asp:UpdatePanel>
When I place this item inside a table (i.e. <table><tr><td>THE CODE ABOVE</td></tr></table>) the panel always shows completely open never hidden. It also completely fills out the available space within the TD and pushes all other text on the page down the screen.
If I take the associated controls out of the table, it works as expected. I have duplicated this issue in both Firefox and IE8.
What gives?

well, with further testing, I was able to prove that this only happens if the control referenced by the dropdownextender is a gridview.
I changed it to a listview control instead and it works as it should.
I assume this is a bug, but I can't find any record of it anywhere.
I also tested to see if it had the same behavior when the gridview was inside a panel that was not referenced by the dropdownextender, but it did not occur. So it's definitely related to the dropdownextender.

Related

FormView.FindControl works for one form but not the other on the same page

I have two Formviews on the same page. I can use FindControl on the first without issue, but it always fails on the second one.
I am using the ItemTemplate for both, both default to ReadOnly, both are bound to SQLDataSources (different ones) but I cannot for the life of me work out why FindControl works for one and not the other.
I have removed a lot of the plain text from the code below.
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:SoftSaleDBConnectionString %>"
SelectCommand="SELECT * FROM [Apps] WHERE ([AppID] = #AppID)" >
<SelectParameters>
<asp:FormParameter FormField="AppID" Name="AppID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="AppID"
DataSourceID="SqlDataSource1">
<ItemTemplate>
<h1>
<asp:Label ID="AppNameLabel" runat="server" Text='<%# Bind("AppName") %>' />
<asp:Label ID="VersionLabel" runat="server" Text='<%# Bind("Version") %>' /> for
<asp:Label ID="OSLabel" runat="server" Text='<%# Bind("OS") %>' />
</h1>
<p>Text here</p>
<p><asp:TextBox ID="LicenseTextBox" runat="server"
Text='<%# Eval("License")%>'
TextMode="MultiLine" Width="800px" Rows="25" ReadOnly="True"></asp:TextBox></p>
<asp:HiddenField ID="AppLocation" runat="server" ViewStateMode="Inherit" Value='<%# Bind("AppLocation") %>'/>
</ItemTemplate>
</asp:FormView>
<p><asp:Literal ID="SizeLiteral" runat="server"></asp:Literal></p>
<asp:SqlDataSource ID="SqlDataSource4" runat="server"
ConnectionString="<%$ ConnectionStrings:SoftSaleDBConnectionString %>"
SelectCommand="SELECT * FROM [Installations] WHERE (([AppID] = #AppID) AND ([Username] = #Username))" >
<SelectParameters>
<asp:FormParameter FormField="AppID" Name="AppID" Type="Int32" />
<asp:FormParameter FormField="Username" Name="Username" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:FormView ID="DLFormView" runat="server" DataSourceID="SqlDataSource4"
DataKeyNames="AppID,Username">
<ItemTemplate>
<p> <asp:Label ID="DLAppNameLabel" runat="server" />
<br />
<br />
<asp:Label ID="NumberOfInstallations" runat="server" Text='<%# Bind("Installations") %>'></asp:Label>
<br />
<asp:HiddenField ID="TotalInstallations" runat="server" />
Number of New Installations:
<asp:DropDownList ID="NumberOfNewInstallations" runat="server">
</asp:DropDownList>
<br />
<asp:Label ID="TotalNumberOfInstallations" runat="server" Text="Label"></asp:Label>
</p>
</ItemTemplate>
</asp:FormView>
And the FindControl coding is as follows...
TextBox LicTextBox = (TextBox)FormView1.FindControl("LicenseTextBox");
HiddenField AppLocCode = (HiddenField)FormView1.FindControl("AppLocation");
Label AppNameCode = (Label)FormView1.FindControl("AppNameLabel");
These always work...
Label DLAppNameCode = (Label)DLFormView.FindControl("DLAppNameLabel");
This always returns null. I've read a million bosts about the controls not being rendered until databinding has completed, but surely if the two FOrmViews are set up the same way, the result should be the same.
Any help would be much apreciated :)
Matt :)
I'd like to plead stupidity and but also provide some background to how I've used what I've learnt from my stupidity.
My SqlDataSource for DLFormView was returning records, of course I then used slightly different values by accident and so no records were returned. I only figured this out by making the ItemTemplate section of the form view only contain unbound (basically plain text) data. As nothing displayed, this pointed towards the page using a different tempalte. When I put a test line in the EmptyDataTemplate, it displayed, confirming there was nothing returned by the SqlDataSource. Perhaps a School boy error not putting something in this template during development.
As it happens I need to use the EmptyDataTemplate anyway, I just hadn't got to this point. As only one template is rendered at a time, I have been able to use the same ID names in both templates. This means there is no need to test for which template is being used. (although empty template is used when DataItemsCount = 0, otherwise you can test for CurrentMode for the remaining templates.)
So a big fail on my part, but I hope people can learn from my mistake.
Matt :)

ASP.NET GridView inside UpdatePanel won't get out of Edit Mode

I have a pretty standard GridView with an SqlDataSource complete with SelectCommand/UpdateCommand/DeleteCommand.
I am utilising the Gridview's built-in commands for TemplateField'ed 's.
CommandName="Update"
CommandName="Edit"
CommandName="Cancel"
CommandName="Delete"
Everything works OK until I put the GridView inside an UpdatePanel.
1. When I click on 'edit' it goes into edit mode but won't get out of edit mode when you click Cancel or Update.
2. When I click on 'delete' performs as it should, however, I won't be able to get into edit mode anymore even if I click 'edit'
What's the matter here?
Example code:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="BoxFloat">
<h4>Aliases</h4>
<hr />
<asp:SqlDataSource ID="sqlPersonAlias" runat="server"
ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
ProviderName="<%$ ConnectionStrings:myConnectionString.ProviderName %>"
DeleteCommand="DELETE FROM PersonAlias WHERE PersonAliasId=?PersonAliasId"
UpdateCommand="UPDATE PersonAlias SET AliasName=?AliasName WHERE PersonAliasId=?PersonAliasId"
SelectCommand="SELECT * FROM PersonAlias E INNER JOIN Person P ON P.PersonId=E.PersonId WHERE Username=?Username">
<DeleteParameters>
<asp:Parameter Name="PersonAliasId" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="PersonAliasId" />
<asp:Parameter Name="AliasName" />
</UpdateParameters>
<SelectParameters>
<asp:QueryStringParameter Name="Username" QueryStringField="Username" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="gridviewPersonAlias" runat="server"
AutoGenerateColumns="False"
DataKeyNames="PersonAliasId"
DataSourceID="sqlPersonAlias">
<Columns>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:ImageButton ID="imagebuttonCancel" ToolTip="Cancel" CommandName="Cancel" ImageUrl="~/images/cancel16.png" runat="server" />
<asp:ImageButton ID="imagebuttonUpdate" ToolTip="Apply" OnClientClick="return confirm('Are you sure?');" CommandName="Update" ImageUrl="~/images/apply16.png" runat="server" />
</EditItemTemplate>
<ItemTemplate>
<asp:ImageButton ID="imagebuttonDelete" ToolTip="Delete" OnClientClick="return confirm('Are you sure?');" CommandName="Delete" ImageUrl="~/images/delete16.png" runat="server" />
<asp:ImageButton ID="imagebuttonEdit" ToolTip="Edit" CommandName="Edit" ImageUrl="~/images/edit16.png" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="AliasName" HeaderText="Alias" SortExpression="AliasName" />
</Columns>
</asp:GridView>
<hr />
<asp:TextBox ID="textboxPersonAlias" runat="server" />
<asp:Button ID="buttonPersonAliasAdd" runat="server" Text="Add" onclick="buttonPersonAliasAdd_Click" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
When "Update" is clicked, the database gets updated. It seems that the problem is just with the client-side.
Note: I'm using "?" instead of "#" for the parameters because that SqlDataSource is using MySq instead of MSSQL (I love VS2010).
I think what you need is full Postback or refresh the update Panel since it is most likely the gridview doesnt rebind
First try to put the sqldatasource outside the update panel. See if that works
I had the same problem in my project, and solved it.
here is my solution:
protected void gvPayments_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//here is the edit code
//......
//at the end add these lines:
gvPayments.EditIndex = -1;
gvPayments.DataBind();
e.Cancel = true;
}

asp SqlDataSource Filter Expression; multiple Search Boxes

I am trying to perform a single search on a single column of data in an asp:GridView, however I want multiple filter (search) boxes above each column so one could search within its own perspective column. What would clearly fix this theoretically is to have multiple FilterExpressions. I am using VB and am very new and easily misunderstood with VB, please bare with:
PS. I have gotten it to work no problem when only having ONE filter (search) box, this currently doesn't do anything
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="xxx"
ProviderName="xxxx"
SelectCommand="SELECT [ddiID], [volusionID], [Customer], [email], [Total], [SumOfTotal] FROM [BBnewsalesQry] ORDER BY [Customer]"
FilterExpression="customer like '%{0}%' OR ddiID like '%{0}%'">
<FilterParameters>
<asp:ControlParameter Name="ddiID" ControlID="ddiIDSearch" PropertyName="Text" />
<asp:ControlParameter Name="customer" ControlID="txtSearch" PropertyName="Text" />
</FilterParameters>
</asp:SqlDataSource>
<div>
<b>DDI Search:</b> <asp:TextBox ID="ddiIDSearch" runat="server" />
<b>Customer Search:</b> <asp:TextBox ID="txtSearch" runat="server" />
<asp:ImageButton ID="btnSearch" ImageUrl="http:xxx" runat="server" />
<asp:ImageButton ID="btnClear" ImageUrl="http:xxx" runat="server" />
</div>
Then inside the GridView:
<asp:TemplateField HeaderText="ddiID" SortExpression="ddiID">
<ItemStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="lblddiid" Text='<%#HighlightText(Eval("ddiid")) %>'
CssClass="TextField" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="volusionID" HeaderText="volusionID" ReadOnly="True" SortExpression="volusionID" />
<asp:TemplateField HeaderText="customer" SortExpression="customer">
<ItemStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="lblcustomer" Text='<%#HighlightText(Eval("customer")) %>'
CssClass="TextField" runat="server" />
</ItemTemplate>
</asp:TemplateField>
you are referencing the same parameter twice - try the following:
FilterExpression="customer like '%{0}%' OR ddiID like '%{1}%'"
I have resolved the problem of create two or more "Like clause" in the "Where" statement using:
Where CHARINDEX(#Par1, Col1)<>0) and ...

Using <asp:EntityDataSource>

I am using EntityDataSource control to display Data in Grid, I want to use the same EntityDataSource to display all data as well as per the search, the problem is I can do only one thing either can use it to search or to get whole data
here is my .aspx page
<asp:EntityDataSource ID="InvestorsSource" runat="server"
ConnectionString="name=Entities"
DefaultContainerName="Entities" EnableFlattening="False"
EntitySetName="Investors" EntityTypeFilter="Investor"
Select="it.[InvestorId], it.[InvestorName], it.[Summary], it.[Logo], it.[EmailAddress], it.[PhoneNumber], it.[Website]"
AutoGenerateWhereClause="True" OrderBy="it.[InvestorName]">
<WhereParameters>
<asp:FormParameter FormField="txtSearchInvestor" Name="investorName" Type="String" />
</WhereParameters>
</asp:EntityDataSource>
<asp:TextBox ID="txtSearchInvestor" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Go" onclick="Button1_Click" />
<p>
<asp:GridView ID="gvInvestors" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False"
DataSourceID="InvestorsSource">
<Columns>
<asp:BoundField DataField="InvestorId" HeaderText="InvestorId" ReadOnly="True"
SortExpression="InvestorId" />
<asp:BoundField DataField="InvestorName" HeaderText="InvestorName"
SortExpression="InvestorName" ReadOnly="True" />
<asp:BoundField DataField="Summary" HeaderText="Summary"
SortExpression="Summary" ReadOnly="True" />
<asp:BoundField DataField="EmailAddress" HeaderText="EmailAddress"
SortExpression="EmailAddress" ReadOnly="True" />
<asp:BoundField DataField="PhoneNumber" HeaderText="PhoneNumber"
SortExpression="PhoneNumber" ReadOnly="True" />
<asp:BoundField DataField="Website" HeaderText="Website"
SortExpression="Website" ReadOnly="True" />
</Columns>
</asp:GridView>
</p>
Thanks
I setup a page using the Northwind DB and using the Employees table. There is a TextBox control and Button controls just like your code to filter the data. When the TextBox is empty, all records are displayed. When a EmployeeID is entered into the TextBox, and the 'Filter' button is clicked, only the employee with the EmployeeID is displayed(if present in the data). I think this is the kind of behavior you are asking for. Here is the markup:
<form id="form1" runat="server">
<div>
<asp:EntityDataSource ID="EntityDataSource1" runat="server"
ConnectionString="name=NWEntities" DefaultContainerName="NWEntities"
EntitySetName="EmployeeSet" EntityTypeFilter="Employee" AutoGenerateWhereClause="true"
Select="it.[EmployeeID], it.[LastName], it.[FirstName], it.[Title], it.[TitleOfCourtesy], it.[BirthDate]">
<WhereParameters>
<asp:FormParameter FormField="txtFilter" Name="EmployeeID" Type="Int32" />
</WhereParameters>
</asp:EntityDataSource>
<asp:TextBox ID="txtFilter" runat="server" />
<asp:Button runat="server" Text="Filter" />
<asp:GridView ID="gvEmployees" runat="server" DataSourceID="EntityDataSource1" AutoGenerateColumns="true" />
</div>
</form>
Edit: The question has been raised as how part of a value could be entered into the filter text box to get all the values that start with the entered value. You could use the LIKE SQL operator and the users would need to be told that the "%" character is the wildcard. I changed the filter to the FirstName field. Here are the changes to the above code:
In the EntityDataSource tag:
AutoGenerateWhereClause="false"
Where="it.[FirstName] LIKE #FirstName"
In the WhereParameters tag:
<asp:FormParameter FormField="txtFilter" Name="FirstName" Type="String" DefaultValue="%" />
Now, when "n%" is entered into the filter textbox, all records with a FirstName value that starts with "n" will be displayed. Any valid LIKE clause could now be used.

Filter gridview

I have a gridview which I am binding through code behind, I want to filter the gridview based on the value given by the user in textbox.
It would be great if I'll be able to filter the gridview without any postback.
PLease help!
Thanks in advance
you could run a filter expression
<asp:sqldatasource id="articles" runat="server"
connectionstring="<%$ ConnectionStrings:aspa %>"
selectcommand="SELECT title, url, added, updated FROM aspx_articles ORDER BY title"
filterexpression="title LIKE '%{0}%' or url LIKE '%{0}%'">
<filterparameters>
<asp:controlparameter controlid="searchBox" propertyname="Text" />
</filterparameters>
</asp:sqldatasource>
or this way
Do you have a TextBox outside the GridView, and when you enter data into it and press a button, the GirdView should be filter on that data?
If so, make sure your select command can taka a parameter with the value you want to filter on. Add a ControlParameter to the SelectParameters colelction of the DataSource control (if you use a DataSource control).
Here is an example that uses the Northwind database, maybe this will help you:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
DataKeyNames="ProductID" DataSourceID="SqlDataSource1" ShowFooter="True">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False"
ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" />
<asp:BoundField DataField="UnitsInStock" HeaderText="UnitsInStock" SortExpression="UnitsInStock" />
<asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [ProductID], [ProductName], [UnitsInStock], [UnitPrice] FROM [Alphabetical list of products] WHERE ([ProductName] LIKE '%' + #ProductName + '%')">
<SelectParameters>
<asp:ControlParameter ControlID="TextBox1" DefaultValue="%" Name="ProductName" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
codes found here http://forums.asp.net/p/1034014/2904713.aspx
If you're using paging, I would recommend using something else (like the Microsoft Ajax Library's dataView). Because gridview paging and client-side filtering wouldn't mesh too well. But if you're not doing paging, you could do something similar to this or this.
The grid view is made for manipulation during post back. If you were to do this entirely on the client side, you'd use a JavaScript suite that would work on any table, not confined to the grid view. If it were me, I would simply use AJAX by wrapping the grid view and text box in an Update Panel. To the end user, the behavior is the same.
EDIT to include Sample code:
<asp:ScriptManager ID="ScriptManager1" AllowCustomErrorsRedirect="false" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox runat="server" ID="txtFilterString" ></asp:TextBox>
<asp:Button runat="server" ID="btnFilter" Text="FilterResults" onclick="btnFilter_Click" />
<asp:GridView runat="server" ID="grdResults"
DataKeyNames="Id"
AllowSorting="true" AllowPaging="true" PageSize="20"
PagerSettings-Mode="NumericFirstLast">
<Columns>
.....
</Columns>
</asp:GridView>
</asp:UpdatePanel>

Resources