RadControls ListView Insert Template Help? - data-binding

I have just started using RadControls so this question might be basic for you, I am using a List View which I am populating using Sql Data Source, I also have insert functionality in that List View but the problem is the insert template just disappear after adding one record and I have to refresh the page to make insert template appear again, am I doing something wrong ?
I have another question regarding Rad List View, is it possible that we use a drop down box instead of a text box inside insert template ? because sometimes you want to restrict the users to pick from predefined values instead of letting them enter anything ? I have tried putting drop down box inside insert template using code view of visual studio and it also appears properly when I run the page but the problem is data binding is not working, I have tried using
SelectedValue=<%# Bind("field_name") %>
as it was used in case of textbox like
Text=<%# Bind("field_name") %)>
but it does not work for some reason.
Please advice,
Thanks.

Ok I got it, maybe it will help someone.
<tr>
<td>
<asp:Label ID="DEPARTMENTLabel2" runat="server"
AssociatedControlID="DEPARTMENTTextBox" Text="DEPARTMENT"></asp:Label>
</td>
<td>
<asp:DropDownList ID="DEPARTMENTTextBox" runat="server" SelectedValue='<%# Bind("DEPARTMENT") %>'>
<asp:ListItem Text="Admin" Value="Admin">Admin</asp:ListItem>
<asp:ListItem Text="Editing" Value="Editing">Editing</asp:ListItem>
<asp:ListItem Text="Sales and Support" Value="Sales and Support">Sales and Support</asp:ListItem>
<asp:ListItem Text="Writing" Value="Writing">Writing</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
Change the default textbox to a dropdown and assign its ID to AssociatedControlID of label that is representing it, here I used the same ID which was originally assigned to it "DEPARTMENTTextBox" (just to be careful), you can change it to "DEPARTMENTDropDown" or any ID you like but make sure you make these changes everywhere in the RADListView so that it performs normally.
As for the insert template disappearing after adding one record, I made a workaround and placed a button for "add another record" such that when it is clicked it calls this code.
protected void btnAddAnother_Click(object sender, EventArgs e)
{
RLVUsers.ShowInsertItem(RadListViewInsertItemPosition.LastItem);
}
This button make insert template reappear and allow the user to add another record.

Related

Refresh asp:UpdatePanel when navigating to other panels in the same container

First off, I'm brand new to ASP.NET so I hope I use the correct terminology. I think that what I have is several asp:UpdatePanels in one ajaxToolKit:TabContainer. One panel has some checkboxes one it, here is the first part of the code for it:
<ajaxToolKit:TabPanel ID="MedicaidDataSubTabReadyToBill" runat="server" HeaderText="Ready To Bill">
<ContentTemplate>
<asp:Label ID="lblReadyToBillMessage" runat="server" Font-Size="X-Small" ForeColor="Red" ></asp:Label>
<asp:UpdatePanel ID="MedicaidDataReadyToBillPanel" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:RegularExpressionValidator ID="regSchoolYear" runat="server"
ControlToValidate="uxMedicaidDataReadyToBill_SchoolYear" ErrorMessage="*invalid school year format." Font-Size="X-Small"
ValidationExpression="^\d{4}$">
</asp:RegularExpressionValidator>
This panel loads some checkboxes, some checked and some not, then I go to another panel in the same container and upload an excel file that should make changes to the database that should affect the check boxes on the first panel. Problem is, when I navigate back to the first panel the changes don't reflect. In order for the changes to show I have to refresh the whole page. Is it possible to have this first panel show the changes without having to refresh the whole page? If so how do I do that? If more code is needed to answer this please let me know. Thanks in advance.
The basic way to update an update panel is simple
MedicaidDataReadyToBillPanel.Update();
When your code that uploads and does db stuff is finished, add that line. Assuming everything else is working, that's all you need.

Checkbox in GridView not persistent ASP.NET

I am having issues with this GridView. I update it in design mode, and the update does not make it to the code behind section. For example, I add field "xyz". Gridview says "xyz" fields exist in design mode. In code-behind, it does not exist. when you view the page in browser, ofcoure "xyz" field is not shown. After refresh, even the gridview looses this field in design mode. So ok I got around this problem and managed to add a template field which is now working.
Now the problem is, the checkbox that I added in one of the column is not persistent. I have a button which works on the selected values of checkboxes but each time I click the button, the page refereshes and all the checked values are lost (checked values becomes unchecked).
Does anyone has any idea?
Want to mention, I am working with a bit messy code. But dont want to change a lot at this time.
<asp:TemplateField HeaderText="All" >
<HeaderTemplate>
<asp:CheckBox ID="chkAll" runat="server" name="chkAll" />
</HeaderTemplate>
<EditItemTemplate>
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkRow" runat="server" />
</ItemTemplate>
</asp:TemplateField>
This took me a couple of days to figure out myself. Since my code was quite messy, it was hard to troubleshoot.
I put in some code in page_load default event that finally fixed. Don't know if I was putting code in the wrong place first. It definitely took some time though.

When radio button selection changes do not cause refresh?

When the selection of the radio buttons change I would like to show/hide the panel in the next table cell. I have it hiding and showing fine but each time it causes the page to refresh to the top. Is their a way to stop that refresh? I would like to hide and show the panel dynamically.
<table>
<tr>
<td>
<asp:RadioButtonList runat="server" ID="rblPlayerStatus" AutoPostBack="true" >
<asp:ListItem>Free Agent</asp:ListItem>
<asp:ListItem>I have teammate</asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
<asp:Panel runat="server" ID="pnlTeamMate">
<asp:Label runat="server" ID="lblTeamMate" Text="Choose Teammate" />
</asp:Panel>
</td>
</tr>
</table>
Use the AJAX.ASP.Net library - then you add a ScriptManager item, and an UpdatePanel. Anything within the UpdatePanel will update through AJAX, not a full page refresh.
Do you have any server side logic based on which show and hide the panel. If yes then you could use update panel control. If it is just client side logic such as
If Free Agent is select show FreeAgent Panel else Team Panel
use javascript or rather jquery to achieve the same.
From your code, I can't see where you hide and show the panel. You could use an updatepanel, but that is best used when you need to retrieve more information from the server.
If you simply want to show and hide the panel, you can do it better with Javascript, by adding some code to the OnClick event to set the panel's visibility css attribute. There are a few tutorials on google about how to do this. Something like this should be sufficient to get you started.
Solution would be either using AJAX (UpdatePanel and ScriptManager) or removing
AutoPostback = true and using JavaScript to display/hide the panel

Delete from grid asp.net

i have this template field inside a gridview.
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:ImageButton ID="ImageButton2" ImageUrl="~/images/DeleteRecord.gif" runat="server"
OnClientClick="return ConfirmacionBorrarClausula();" CommandName="BorrarClausula" CommandArgument='<%#Eval("ClausulaID")%>' OnCommand="gvClausulas_OnRowDeleting" CausesValidation="false"
</ItemTemplate>
</asp:TemplateField>
I have another one in the same page but in a different gridview, almost exactly like this one but the second one isnĀ“t working.
So i have two gridviews each one with a template field like the one here, one onRowDeleting working perfectly, the other one not working at all, when i click it, it asks for confirmation (javascript function) but when i click ok to delete, the grid loses it data and the page fires all the validators.
Thank you for your time.
Make sure the control IDs are set right. And Ispostback the control level set to true. And also Try deleting the control and add it again some time that might help. Try add it from design view.
i manage to solve it, the problem was the second gridview was losing its data on the pageload, i managed that but only with the first gridview.

One user control updating another during AJAX Postback?

I developed a user control that displays a list of products and it works pretty good. Then I dropped this user control into another user control that allows the user to pick different criteria and the product UC updates to show those products, all pretty slick and with AJAX via UpdatePanel.
All was working just fine... then another requirement came in. The "search" control needs to be separate from the product control (so they can be positioned separately). Initially, I thought this was no problem as I would give the search control a reference to the product control and then it would talk to it via reference instead of directly inside the control (which has been removed).
And they do talk. But the product control loads, but refuses to display.
I checked and it is being passed via reference and not a copy ( as best I can tell ).
There is an updatepanel in the search control. There is an update panel in the product control. And then for good measure, there is an update panel surrounding them both in the actual search aspx page.
I've tried setting the product control update panel to conditional and then fire the .Update() method manually.
What's the secret here?
TIA!
SOLVED
Thanks to Jamie Ide for the tip to use events.
Search Control and Product control still have internal update panels, and NO LONGER have them on this particular page.
Search Control now raises an event OnSearchResultsUpdated and exposes the found items in properties. The page subscribes to this event and takes the properties and passes them to the product control and triggers triggers a .Refresh() method on the product control which simply calls the .Update() on its internal updatepanel.
The Product control, FYI, accepts products in several different flavors. A list of distinct SKUs, a list of product ids, a named collection in our database and finally a given product category.
Our designers need to be able to create a new page, drop the control onto it and set some properties and voila! New site page. They don't want to require a programmer's involvement. So keeping the controls self contained is a requirement. Fortunately all the changes I made still work completely with the other uses of the product control.
THANKS AGAIN SO MUCH!
I don't think there's really enough information to work with here, but my best guess is that the Product control is not getting data bound. You may try calling myProdcutsCtrl.DataBind() from the search control (or something inside the Product control that cause a DataBind() for instance myProductCtrl.Search(value1, value2, value3).
One other thing you might try is removing the UpdatePanels and seeing if things work. Then add them back in once you get core functionality going.
UPDATE: I've gone ahead and put some example code that works here which I believe accomplishes what you want. What follows are snippets for the sake of saving space, but include all code necessary to make it run. Hopefully this will at least give you something for reference.
Things to try:
EnablePartialRendering="true|false" setting it to false will force the natural postbacks and is good for debugging UpdatePanel problems.
Make sure you are seeing Loading... come up on your screen. (maybe too fast depending on your dev computer)
Page.aspx
<%# Register Src="~/Product.ascx" TagPrefix="uc" TagName="Product" %>
<%# Register Src="~/Search.ascx" TagPrefix="uc" TagName="Search" %>
...
<asp:ScriptManager runat="server" ID="sm" EnablePartialRendering="true" />
Loaded <asp:Label ID="Label1" runat="server"><%= DateTime.Now %></asp:Label>
<asp:UpdateProgress runat="server" ID="progress" DynamicLayout="true">
<ProgressTemplate><b>Loading...</b></ProgressTemplate>
</asp:UpdateProgress>
<uc:Search runat="server" ID="search" ProdcutControlId="product" />
<uc:Product runat="server" ID="product" />
Search.ascx
<asp:UpdatePanel runat="server" ID="searchUpdate" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<p>
<asp:Label runat="server" AssociatedControlID="filter">Less than</asp:Label>
<asp:TextBox runat="server" ID="filter" MaxLength="3" />
<asp:Button runat="server" ID="search" Text="Search" OnClick="SearchClick" />
</p>
</ContentTemplate>
</asp:UpdatePanel>
Search.ascx.cs
public string ProdcutControlId { get; set; }
protected void SearchClick(object sender, EventArgs e)
{
Product c = this.NamingContainer.FindControl(ProdcutControlId) as Product;
if (c != null)
{
c.Search(filter.Text);
}
}
Product.ascx
<asp:UpdatePanel runat="server" ID="productUpdate" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<asp:Label runat="server">Request at <%= DateTime.Now %></asp:Label>
<asp:ListView runat="server" ID="product">
<LayoutTemplate>
<ul>
<li id="itemPlaceHolder" runat="server" />
</ul></LayoutTemplate>
<ItemTemplate>
<li><%# Container.DataItem %></li></ItemTemplate>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
Product.ascx.cs
IEnumerable<int> values = Enumerable.Range(0, 25);
public void Search(string val)
{
int limit;
if (int.TryParse(val, out limit))
product.DataSource = values.Where(i => i < limit);
else
product.DataSource = values;
product.DataBind();
productUpdate.Update();
}
Code does NOT represent best practices, just a simple example!
I'm fairly new to AJAX, but I don't think it's a good idea for user controls to have UpdatePanels. I would also advise you not to have the user controls reference each other; they should communicate through events and methods controlled by their container.
I do something similar with two user controls for a master-details display. The master raises an event when an item is selected from a list, the containing page handles the event and calls a method on the details display to display the selected item. If I remember correctly, my first attempt had UpdatePanels in the user controls and I wasn't able to make that work. Having the user controls inside an UpdatePanel on the page works fine.
If I understand you right you have a layout like this:
Outer UpdatePanel
SearchControl
Search UpdatePanel
ProductControl
Product UpdatePanel
Databound Control
Which one of those update panels is actually being called?
I assume that if you check the network traffic with something like Fiddler or Firebug if you're using Firefox, you aren't seeing any HTML for the product update panel coming back?
Have you tried doing something like:
UpdatePanel productUpdate =
Page.FindControl("Product UpdatePanel") as UpdatePanel;
if (null != productUpdate){
productUpdate.Update();
}
By default, if a postback is made from an UpdatePanel, only that control will be updated/re-rendered (this is called partial page-rendering).
To also update/re-render other UpdatePanels, you have to either:
set their UpdateMode property to Always
add the control that makes the postback to their Triggers collection
Check this page in MSDN for details.

Resources