Showing posts with label detailsview. Show all posts
Showing posts with label detailsview. Show all posts

Monday, March 26, 2012

Detailsview ItemUpdate Event with UpdatePanel

I have a grid with individuals in it, the user selects and individual which populates a Detailsview below. Both gridview and Detailsview are wrapped with UpdatePanels. The user can then edit the individual in the Detailsview and submit changes when updateing. Now the updatepanel wrapping the gridview has an <asp:AsyncPostBackTrigger tied back to the Detailsview's ItemUpdated event.

I ultimately want the grid of selected individuals to update whenever the user makes changes to the individuals through the supporting gridview, the trigger I am using is not providing the functionality I am looking for, what approach should I take next? or is this trigger not working properly?

I can provide code-snippets, but figured it would be better to get a high level overview then look at some of my mess :)

Thanks in advance to anyone who offers help.

Here are some sample codes for your reference.
.ASPX
<div>
<asp:UpdatePanel ID="gvUpnl" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="gvProduct" runat="server" AutoGenerateSelectButton="true" AutoGenerateEditButton="true" AutoGenerateDeleteButton="true" AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True" DataKeyNames="ProductID" DataSourceID="sqlDS" OnRowCommand="gvProduct_RowCommand">
<Columns>
<asp:TemplateField HeaderText="ProductID" SortExpression="ProductID">
<ItemTemplate>
<asp:Label ID="lblProductID" runat="server" Text='<%# Eval("ProductID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" />
<asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" />
<asp:BoundField DataField="Quantity" HeaderText="Quantity" SortExpression="Quantity" />
<asp:BoundField DataField="TransactionDate" HeaderText="TransactionDate" ReadOnly="True"
SortExpression="TransactionDate" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="sqlDS" runat="server" ConnectionString="<%$ ConnectionStrings:ProductConnectionString %>" DeleteCommand="DELETE FROM [Product] WHERE [ProductID] = @.ProductID" InsertCommand="INSERT INTO [Product] ([ProductName], [UnitPrice], [Quantity], [TransactionDate]) VALUES (@.ProductName, @.UnitPrice, @.Quantity, @.TransactionDate)" SelectCommand="SELECT [ProductID], [ProductName], [UnitPrice], [Quantity], [TransactionDate] FROM [Product]" UpdateCommand="UPDATE [Product] SET [ProductName] = @.ProductName, [UnitPrice] = @.UnitPrice, [Quantity] = @.Quantity, [TransactionDate] = @.TransactionDate WHERE [ProductID] = @.ProductID">
<DeleteParameters>
<asp:Parameter Name="ProductID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="ProductName" Type="String" />
<asp:Parameter Name="UnitPrice" Type="Double" />
<asp:Parameter Name="Quantity" Type="Int32" />
<asp:Parameter Name="TransactionDate" Type="DateTime" />
<asp:Parameter Name="ProductID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="ProductName" Type="String" />
<asp:Parameter Name="UnitPrice" Type="Double" />
<asp:Parameter Name="Quantity" Type="Int32" />
<asp:Parameter Name="TransactionDate" Type="DateTime" />
</InsertParameters>
</asp:SqlDataSource>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="gvProduct" EventName="RowCommand" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="dvUpnl" runat="server">
<ContentTemplate>
<asp:DetailsView ID="dvProduct" runat="server" DataKeyNames="ProductID" AllowPaging="True" DataSourceID="dvDS" AutoGenerateEditButton="true" AutoGenerateInsertButton="true" AutoGenerateDeleteButton="true">
</asp:DetailsView>
<asp:SqlDataSource ID="dvDS" runat="server" ConnectionString="<%$ ConnectionStrings:ProductConnectionString %>">
<SelectParameters>
<asp:Parameter Name="ProductID" Type="Int32" Direction="Input" DefaultValue="1"/>
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="ProductID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="ProductID" Type="Int32" Direction="Input" />
<asp:Parameter Name="ProductName" Type="String" />
<asp:Parameter Name="UnitPrice" Type="double" />
<asp:Parameter Name="Quantity" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
</ContentTemplate>
</asp:UpdatePanel>
</div
Behind Code:
protected void Page_Load(object sender, EventArgs e)
{
string cString = System.Configuration.ConfigurationManager.AppSettings["ProductConnectionString"];
dvDS.ConnectionString = cString;
dvDS.SelectCommand = "SELECT ProductID,ProductName,UnitPrice,Quantity,TransactionDate FROM Product WHERE ProductID=@.ProductID";
dvDS.UpdateCommand = "UPDATE Product SET ProductName=@.ProductName,UnitPrice=@.UnitPrice,Quantity=@.Quantity WHERE ProductID=@.ProductID";
}

protected void gvProduct_RowCommand(object sender, GridViewCommandEventArgs e)
{
Label lblProductID = gvProduct.Rows[int.Parse(e.CommandArgument.ToString())].FindControl("lblProductID") as Label;
string productID = lblProductID.Text;
if(e.CommandName == "Select")
{
dvDS.SelectParameters["ProductID"].DefaultValue = productID;
}
else if(e.CommandName == "Edit")
{}
else if(e.CommandName == "Delete")
{}
}
Wish the above can help you.

DetailsView Inside of a Modal Popup

I'm using a DetailsView to insert new records into a database as well as edit existing records. The Modal is called via ModalPopupExtender.Show() when a LinkButton is clicked and then hidden when the LinkButtons on the DetailsView are clicked. The Functions of the modal popup seem to work fine as well as the Insert() Update() methods of the DetailsView. The problem I'm having is with updating the Text property of the LinkButton at the bottom of the DetailsView to change it from "Add" to "Save" depending on the DetailsView.CurrentMode that I'm changing to/from. I've tried using Update Panels around the LinkButtons only in the DetailsView and then I added an AsyncPostBack trigger for the LinkButton that pops the modal DetailsView in Insert mode and an AsyncPostBack that pops the modal DetailsView in Edit mode from the GridView I have on the page. Then I added a PostBack trigger to handle clicks of the LinkButton on the DetailsView for Insert/Update (depending on the mode) and then Cancel. Both of the postbacks close the modal successfully, it's the AsyncPostBacks that are not updating the Modal DetailsView to show the right Text on the one LinkButton I'm trying to update. Any help would be appreciated. Here is the code:

1protected void Page_Load(object sender, EventArgs e)2 {34 }5protected void AddCategory_OnClick(object sender, EventArgs e)6 {7 ModalPopupExtender1.Show();8 CategoryDetailsView.ChangeMode(DetailsViewMode.Insert);910 }11protected void UpdateInsert_OnClick(object sender, EventArgs e)12 {13if (CategoryDetailsView.CurrentMode == DetailsViewMode.Insert)14 {15 CategoryDetailsView.InsertItem(true);16 }17if (CategoryDetailsView.CurrentMode == DetailsViewMode.Edit)18 {19 CategoryDetailsView.UpdateItem(true);20 }21 }22protected void Cancel_OnClick(object sender, EventArgs e)23 {24 ModalPopupExtender1.Hide();25 CategoryDetailsView.ChangeMode(DetailsViewMode.ReadOnly);2627 }28private LinkButton updateinsertbtn29 {30get31 {32 LinkButton udtisrtbtn;33 udtisrtbtn = (LinkButton)CategoryDetailsView.FindControl("UpdateInsertLinkBtn");34return udtisrtbtn;35 }36 }37private int index38 {39get40 {41return CategoryGridView.SelectedIndex;42 }43 }44protected void CategoryGridView_OnSelectedIndexChanged(object sender, EventArgs e)45 {46 CategoryDetailsView.ChangeMode(DetailsViewMode.Edit);47if (index != -1)48 {49 ModalPopupExtender1.Show();50 CategoryGridView.DataSourceID =null;51 CategoryTableAdapter categoryAdapter =new CategoryTableAdapter();52 CategoryGridView.DataSource = categoryAdapter.GetCategories();53 CategoryGridView.SelectedIndex = index;54int categoryid = Convert.ToInt32(((Categories.CategoryDataTable)CategoryGridView.DataSource).Rows[CategoryGridView.SelectedRow.DataItemIndex]["CategoryID"]);55 SqlDataSource1.SelectCommand ="Select CategoryName, CategoryDescription, CategoryID from Category where CategoryID = " + categoryid;5657 CategoryDetailsView.DataBind();58 CategoryGridView.DataSource =null;59 CategoryGridView.DataSourceID ="SqlDataSource1";60 SqlDataSource1.SelectCommand ="Select CategoryID, CategoryName, CategoryDescription from Category Order by CategoryName";61 CategoryGridView.DataBind();6263 }64 }

<asp:ContentID="Content1"ContentPlaceHolderID="maincontent"Runat="Server">
<script>
function okScript()
{
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm._doPostBack('UpdatePanel1','');
}
</script>
<asp:ScriptManagerid="ScriptManager1"runat="server"></asp:ScriptManager>
<table>
<tr>
<tdvalign="top"style="padding:5px;line-height:1.6em;">

<asp:HyperLinkID="AddCatLinkButton"runat="server"Text="Add New Category"NavigateUrl="javascript:NewCategory('addCategory.aspx');"></asp:HyperLink><br/>

<asp:LinkButtonID="AddCategoryLinkButton"runat="server"Text="Add New Category"OnClick="AddCategory_OnClick"></asp:LinkButton>

</td>

<tdvalign="top">

<asp:UpdatePanelid="UpdatePanel1"runat="server"UpdateMode="Conditional">

<contenttemplate>

<asp:GridViewid="CategoryGridView"runat="server"DataSourceID="SqlDataSource1"CellPadding="3"DataKeyNames="CategoryID"AutoGenerateColumns="False"OnSelectedIndexChanged="CategoryGridView_OnSelectedIndexChanged">

<Columns>

<asp:CommandFieldHeaderText="Edit"ShowSelectButton="true"SelectText="Edit"/>

<asp:BoundFieldDataField="CategoryID"HeaderText="CategoryID"InsertVisible="False"ReadOnly="True"SortExpression="CategoryID"Visible="False"/>

<asp:BoundFieldDataField="CategoryName"HeaderText="Name"SortExpression="CategoryName"/>

<asp:BoundFieldDataField="CategoryDescription"HeaderText="Description"SortExpression="CategoryDescription"/>

<asp:TemplateFieldHeaderText="Remove Category">

<ItemTemplate>

<asp:LinkButtonID="DeleteButton"runat="server"Text="Remove"CommandName="Delete"></asp:LinkButton>

</ItemTemplate>

<ItemStyleHorizontalAlign="Center"/>

</asp:TemplateField>

</Columns>

<EmptyDataTemplate>

There are no categories to display.

</EmptyDataTemplate>

</asp:GridView>

</contenttemplate>

</asp:UpdatePanel>

</td>

</tr> </table>

<asp:PanelID="CategoryPanel"runat="server"GroupingText="Product Category"Style="display:none;"CssClass="modalPopup">

<asp:DetailsViewID="CategoryDetailsView"runat="server"AutoGenerateRows="False"DataKeyNames="CategoryID"DefaultMode="ReadOnly"

DataSourceID="SqlDataSource1"CellPadding="3"CssClass="TextBox"OnModeChanged="CategoryDetailsView_OnModeChanged">

<Fields>

<asp:BoundFieldDataField="CategoryID"HeaderText="CategoryID"InsertVisible="False"

ReadOnly="True"SortExpression="CategoryID"Visible="False"/>

<asp:BoundFieldDataField="CategoryName"HeaderText="Name"SortExpression="Name"/>

<asp:BoundFieldDataField="CategoryDescription"HeaderText="Description"

SortExpression="Description"/>

</Fields>

<FooterTemplate>

<asp:UpdatePanelID="LinkUpdate"runat="server"EnableViewState="true"UpdateMode="Always"RenderMode="Inline">

<ContentTemplate>

<asp:LinkButtonID="UpdateInsertLinkBtn"runat="server"Text="Test"OnClick="UpdateInsert_OnClick"></asp:LinkButton>

</ContentTemplate>

<Triggers>

<asp:AsyncPostBackTriggerControlID="AddCategoryLinkButton"EventName="Click"/>

<asp:AsyncPostBackTriggerControlID="CategoryGridView"EventName="SelectedIndexChanged"/>

<asp:PostBackTriggerControlID="UpdateInsertLinkBtn"/>

<asp:PostBackTriggerControlID="CancelButton1"/>

</Triggers>

</asp:UpdatePanel>

<asp:LinkButtonID="CancelButton1"runat="server"Text="Cancel"OnClick="Cancel_OnClick"></asp:LinkButton>

</FooterTemplate>

</asp:DetailsView>

<divalign="center">

<asp:LinkButtonID="OkButton"runat="server"></asp:LinkButton> <asp:LinkButtonID="CancelButton"runat="server"></asp:LinkButton>

</div>

</asp:Panel>

<ajaxToolkit:ModalPopupExtenderID="ModalPopupExtender1"runat="server"TargetControlID="AddCatLinkButton"CancelControlID="CancelButton"OkControlID="Okbutton"

PopupControlID="CategoryPanel"OnOkScript="okScript()"BackgroundCssClass="modalBackground"DropShadow="true">

</ajaxToolkit:ModalPopupExtender>

<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:IT_ASSETDbase %>"

DeleteCommand="DELETE FROM [Category] WHERE [CategoryID] = @dotnet.itags.org.CategoryID"

InsertCommand="INSERT INTO [Category] ([CategoryName], [CategoryDescription]) VALUES (@dotnet.itags.org.CategoryName, @dotnet.itags.org.CategoryDescription)"

SelectCommand="SELECT 'javascript:NewCategory(''editCategory.aspx?CategoryID=' + CAST(CategoryID AS nvarchar) + ''');' AS URL, CategoryID, CategoryName, CategoryDescription FROM Category"

UpdateCommand="UPDATE [Category] SET [CategoryName] = @dotnet.itags.org.CategoryName, [CategoryDescription] = @dotnet.itags.org.CategoryDescription WHERE [CategoryID] = @dotnet.itags.org.CategoryID">

<DeleteParameters>

<asp:ControlParameterControlID="CategoryGridView"Name="CategoryID"PropertyName="SelectedValue"Type="Int32"/>

</DeleteParameters>

<UpdateParameters>

<asp:ParameterName="CategoryName"Type="String"/>

<asp:ParameterName="CategoryDescription"Type="String"/>

<asp:ParameterName="CategoryID"Type="Int32"/>

</UpdateParameters>

<InsertParameters>

<asp:ParameterName="CategoryName"Type="String"/>

<asp:ParameterName="CategoryDescription"Type="String"/>

</InsertParameters>

</asp:SqlDataSource>

</asp:Content>

">

I was unable to accomplish changing the Text property value to what I wanted but I ended up modifying the code to remove the Update Panels in order to get modal DetailsView to Insert and Edit records and then update the GridView control by calling GridView.DataBind() after the Update() or Insert() methods were called for the DetailsView. Not exactly what I wanted but works.

Detailsview in updatepanel with dropdownlist SelectedIndexChanged to update textbox(s) val

I am new to the updatepanel and need some help. I have a gridview control and a detailsview control. The detailsview control is displayed for edits on the gridview row select command. These controls are wrapped in an updatepanel, there are 2 textboxes that I want to update with calculated values based on the selected value of the dropdownlist. I was trying to accomplish this by using the SelectedIndexChanged of the ddlScheduleType dropdownlist in codbehind.

How do I get this to work, am I on the right track? Any help would be greatly appreciated, code is below.

Protected

Sub ddlScheduleType_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)'Get a refernce to the dropdownlist:Dim ddlScheduleTypeAs DropDownList =CType(CType(sender, DetailsView).FindControl("ddlScheduleType"), DropDownList)Dim nDistroyDaysAsInteger = Utility.GetBoxCatDestroyDays(ddlScheduleType.SelectedValue)Dim ctrlTbDYAs TextBox =CType(CType(sender, DetailsView).FindControl("tbDestroyYear"), TextBox)Dim ctrlTbDMAs TextBox =CType(CType(sender, DetailsView).FindControl("tbDestroyMonth"), TextBox)Dim ctrlTbDEAs TextBox =CType(CType(sender, DetailsView).FindControl("tbDateEnd"), TextBox)

<%

@dotnet.itags.org.PageLanguage="VB"MasterPageFile="~/Default.master"AutoEventWireup="false"CodeFile="drEdit.aspx.vb"Inherits="drEdit"title="Untitled Page" %>

<%

@dotnet.itags.org.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="ajaxtoolkit" %>

<%

@dotnet.itags.org.RegisterNamespace="CustomBoundField"TagPrefix="custom" %>

<

asp:ContentID="Content1"ContentPlaceHolderID="MainContent"Runat="Server">

<

ajax:ScriptManagerid="sm1"EnablePartialRendering="True"runat="server"/><table><tr><tdalign="Center"valign="Top"><ajax:UpdatePanelid="up2"runat="server"><contentTemplate><asp:GridViewRunat="server"Id="gvDrMaster"GridLines="Both"cellpadding="1"cellspacing="0"Headerstyle-BackColor="#BDCFE7"Headerstyle-Font-Names="Verdana,Helvetica,Arial;"Headerstyle-Font-Size="8"BackColor="#E7EFFF"Font-Names="Verdana,Helvetica,Arial;"Font-Size="8"BorderColor="Black"DataSourceID="SqlDsMaster"DataKeyNames="dr_id"AllowPaging="True"AllowSorting="True"PageSize="50"AutoGenerateColumns="False"><Columns><asp:CommandFieldShowSelectButton="True"/><asp:BoundFieldDataField="box_barcode"HeaderText="Barcode"/><asp:BoundFieldDataField="box_description"HeaderText="Description"HeaderStyle-HorizontalAlign=LeftItemStyle-HorizontalAlign=left/><asp:BoundFieldDataField="box_location"HeaderText="Location"/><asp:BoundFieldDataField="status_name"HeaderText="Status"/><asp:BoundFieldDataField="site_name"HeaderText="Site"/><asp:BoundFieldDataField="dr_id"ReadOnly="True"HeaderText=""HeaderStyle-Width="0"/><asp:BoundFieldDataField="box_site"ReadOnly=trueHeaderText=""HeaderStyle-Width="0"/></Columns><SelectedRowStyleBackColor=AliceBlue/></asp:GridView><triggers><ajax:controlValueTriggercontrolid="gvDrmaster"propertyname="Select"/></triggers></contentTemplate></ajax:UpdatePanel></td><tdalign="Left"valign="Top"><ajax:UpdatePanelid="up1"UpdateMode=Alwaysrunat="server"><contentTemplate><asp:DetailsViewDataKeyNames="dr_id"DataSourceID="SqlDsDetail"GridLines="Both"cellpadding="1"cellspacing="0"Headerstyle-BackColor="#BDCFE7"Headerstyle-Font-Names="Verdana,Helvetica,Arial;"Headerstyle-Font-Size="8"BackColor="#E7EFFF"Font-Names="Arial"Font-Size="8"BorderColor="Black"HeaderText="Author Details"AutoGenerateRows="False"HeaderStyle-Font-Bold="True"OnItemUpdated="DVAfterUpdate"ID="dvDrMaster"runat="server"><Fields><asp:BoundFieldDataField="dr_id"HeaderText="ID"ReadOnly="True"ControlStyle-CssClass="dvDataField"/><asp:BoundFieldDataField="box_barcode"HeaderText="Barcode"ControlStyle-CssClass="dvDataField"/><custom:BoundTextBoxFieldCssClass="dvDataField"DataField="box_description"HeaderText="Description"TextMode="MultiLine"Rows="5"Columns="50"Wrap="True"/><asp:TemplateFieldHeaderText="Box Category"><ItemTemplate><asp:Labelid="lblScheduleType"runat="server"Text='<%# Container.DataItem("schedule_record_type")%>'/></ItemTemplate><EditItemTemplate><asp:DropDownListrunat="server"id="ddlScheduleType"DataSourceID="dsScheduleType"SkinID=ddlBackColor="Pink"DataTextField="schedule_record_type"DataValueField="schedule_id"AutoPostBack=trueOnSelectedIndexChanged="ddlScheduleType_SelectedIndexChanged"SelectedValue='<%# Bind("box_schedule_type")%>'/></EditItemTemplate></asp:TemplateField>

<asp:TemplateFieldHeaderText="Status"><ItemTemplate><asp:Labelid="lblStatus"runat="server"Text='<%# Container.DataItem("status_name")%>'/></ItemTemplate><EditItemTemplate><asp:DropDownListrunat="server"id="ddlStatus"DataSourceID="dsStatus"SkinID=ddlBackColor="Pink"DataTextField="status_name"DataValueField="status_id"SelectedValue='<%# Bind("box_status")%>'/></EditItemTemplate></asp:TemplateField>

<asp:TemplateFieldHeaderText="Site"><ItemTemplate><asp:Labelid="lblSiteName"runat="server"Text='<%# Container.DataItem("site_name")%>'/></ItemTemplate><EditItemTemplate><asp:DropDownListrunat="server"id="ddlSite"DataSourceID="dsSite"BackColor="Pink"SkinID=ddlDataTextField="site_name"DataValueField="site_id"SelectedValue='<%# Bind("box_site")%>'/></EditItemTemplate></asp:TemplateField>

<asp:TemplateFieldHeaderText="Box Location"><ItemTemplate><asp:Labelid="lblLocation"runat="server"Text='<%# Container.DataItem("box_location")%>'/></ItemTemplate><EditItemTemplate><asp:DropDownListrunat="server"id="ddlBoxLocation"DataSourceID="SQLDSLocation"BackColor="Pink"SkinID=ddlDataTextField="location_id"DataValueField="location_id"SelectedValue='<%# Bind("box_location")%>'/></EditItemTemplate></asp:TemplateField>

<asp:TemplateFieldHeaderText="Cardholder Data"><ItemTemplate><asp:Labelid="lblCardholder"runat="server"Text='<%# Container.DataItem("box_cardholder_desc")%>'/></ItemTemplate><EditItemTemplate><asp:DropDownListrunat="server"id="ddlCardholder"BackColor="Pink"SkinID=ddlDataTextField="box_cardholder_desc"DataValueField="box_cardholder"SelectedValue='<%# Bind("box_cardholder")%>'><asp:ListItemSelected="True"Value=""Text=""/><asp:ListItemValue="Y"Text="Yes"/><asp:ListItemValue="N"Text="No"/></asp:DropDownList>

</EditItemTemplate></asp:TemplateField>

<asp:TemplateFieldHeaderText="Dept"><ItemTemplate><asp:Labelid="lblDept"runat="server"Text='<%# Container.DataItem("dept_name")%>'/></ItemTemplate><EditItemTemplate><asp:DropDownListrunat="server"id="ddlDept"DataSourceID="SQLdsDepartment"BackColor="Pink"SkinID=ddlDataTextField="dept_name"DataValueField="dept_id"SelectedValue='<%# Bind("fiserv_dept")%>'/></EditItemTemplate></asp:TemplateField>

<asp:BoundFieldDataField="date_start"HeaderText="Start Date"ControlStyle-CssClass="dvDataField"/>

<asp:TemplateFieldHeaderText="End Date"><ItemTemplate><asp:Labelid="lblDateEnd"runat="server"Text='<%# Container.DataItem("date_end")%>'/></ItemTemplate><EditItemTemplate><asp:TextBoxID="tbDateEnd"SkinID=tbrunat="server"Text='<%# Bind("date_end")%>'/></EditItemTemplate></asp:TemplateField>

<asp:TemplateFieldHeaderText="Destroy Month"><ItemTemplate><asp:Labelid="lblDestroyMonth"runat="server"Text='<%# Container.DataItem("date_dest_month")%>'/></ItemTemplate><EditItemTemplate><asp:TextBoxID="tbDestroyMonth"SkinID=tbrunat="server"ReadOnly=trueText='<%# Bind("date_dest_month")%>'/></EditItemTemplate></asp:TemplateField>

<asp:TemplateFieldHeaderText="Destroy Year"><ItemTemplate><asp:Labelid="lblDestroyYear"runat="server"Text='<%# Container.DataItem("date_dest_year")%>'/></ItemTemplate><EditItemTemplate><asp:TextBoxID="tbDestroyYear"SkinID=tbrunat="server"ReadOnly=trueText='<%# Bind("date_dest_year")%>'/></EditItemTemplate></asp:TemplateField>

<asp:CommandFieldShowEditButton="True"/></Fields></asp:DetailsView><Triggers><atlas:ControlEventTriggerControlID="ddlScheduleType"EventName="SelectedIndexChanged"/></Triggers></contentTemplate>

</ajax:UpdatePanel>

</td></tr></table><asp:SqlDataSourceID="SqlDsMaster"runat="server"SelectCommand="select dr_id, box_barcode, box_description, box_location, status_name, box_site, site_name from view_dr_master where box_site not in(97,98)"ConnectionString="<%$ ConnectionStrings:RetentionConnectionString%>"></asp:SqlDataSource><asp:SqlDataSourceID="SqlDsDetail"runat="server"ConnectionString="<%$ ConnectionStrings:RetentionConnectionString%>"SelectCommand="SELECT dr_id, box_barcode, box_schedule_type, box_description, box_location, box_status, status_name, box_site, site_name, fiserv_dept, dept_name,

date_start, date_end, date_dest_month, date_dest_year, box_cardholder, box_cardholder_desc

FROM view_dr_master WHERE (dr_id = @dotnet.itags.org.dr_id)">

<SelectParameters><asp:ControlParameterControlID="gvDrMaster"Name="dr_id"PropertyName="SelectedValue"Type="String"/></SelectParameters></asp:SqlDataSource>

<asp:SQLDataSourceID="dsScheduleType"Runat="Server"SelectCommand="SELECT schedule_id, schedule_record_type from dr_schedule GROUP BY schedule_id, schedule_record_type Union Select 0 schedule_id, 'Please select a box category' schedule_record_type From dr_schedule ORDER BY schedule_record_type"DataSourceMode="DataSet"ConnectionString="<%$ ConnectionStrings:RetentionConnectionString%>"></asp:SQLDataSource><asp:SQLDataSourceID="dsStatus"Runat="Server"SelectCommand="SELECT status_id, status_name from dr_status Union Select '' status_id, 'Please select a box status.' status_name from dr_status ORDER BY status_id "DataSourceMode="DataSet"ConnectionString="<%$ ConnectionStrings:RetentionConnectionString%>"/><asp:SQLDataSourceID="dsSite"Runat="Server"SelectCommand="select site_id, site_name from dr_site order by site_id"DataSourceMode="DataSet"ConnectionString="<%$ ConnectionStrings:RetentionConnectionString%>"/><asp:SQLDataSourceID="SQLDSLocation"Runat="Server"DataSourceMode="DataSet"ConnectionString="<%$ ConnectionStrings:RetentionConnectionString%>"></asp:SQLDataSource>

<asp:SQLDataSourceID="SQLdsDepartment"Runat="Server"SelectCommand="select dept_id, dept_name from dr_departments"DataSourceMode="DataSet"ConnectionString="<%$ ConnectionStrings:RetentionConnectionString%>"/>

</

asp:Content>Dim dtDestroyDateAs DateTime = dtDestroyDate.AddDays(nDistroyDays)

ctrlTbDY.Text = dtDestroyDate.Year

ctrlTbDM.Text = dtDestroyDate.Month

EndSub

Never mind figured it out, removed

<Triggers><atlas:ControlEventTriggerControlID="ddlScheduleType"EventName="SelectedIndexChanged"/></Triggers>

Detailsview in UpdatePanel - Master$Content$dvParameters$ctl03 could not be located...

Hi,

I have this weird problem that just started to happen today and I have no idea what caused it:

I have a DetailsView bound to a SqlDataSource in an UpdatePanel. Whenever I edit something in the DetailsView and initiate the async postback, I get:

"An error has occurred because a control with id 'Master$Content$dvParameters$ctl03' could not be located or a different control is assigned the sameID after postback".

Any idea what could be wrong here?

Thanks,

Tom

Ok, I've found out that this happened because I accidentally changed the MasterPage ID in its OnLoad method rather than in the OnInit method

DetailsView in a modalpopup

Hello,

i am using a detailsview in a modalpopup. When i click edit in the detailsview, the popup closes again. I have a cancel button separately to close the popup. How do i prevent the popup from closing when i press the Detailsview?

thanks for your kind help.

Maurice

I am having a very similiar problem as you.

I have a usercontrol that contains some textbox's, a button and a gridview.

When I click the button I filter the gridview based on content from the textbox's

The usercontrol is inside a modalpopup. When I click on the button, the modalpopup disappears. The popup should not disappear!


I started to encounter this problem after I upgraded from Beta2 to RTM of AJAX.NET Extensions and got the latest version of the Control Toolkit.

Is there anyone with any solutions?!?


Hi,

ModalPopup will hide whenever a postback occurs (well, technically it doesn't hide but rather it won't be shown again). If the content of your ModalPopup is causing postbacks, you should wrap it in an UpdatePanel (just the content of the ModalPopup - not the whole ModalPopup itself) so the popup remains visible.

Thanks,
Ted


Hi, I have a modal popup which shows search results.It uses updatepanel as you mentioned and on a button click I fill an asp-repeater control.

After searching (repeater is populated), if I click the cancel button of the popupextender then

the dropdown boxes on the page remain invisible..Is this a bug ? appreciate any solution. Thanks.

DetailsView and ControlID

Hello

I need to force DetailsView to expose its fields
with a TargetControlID. I add these fields to DetailsView:

BoundField bf = new BoundField();
bf.DataField = sField;
bf.HeaderText = sHeader;
myDetailsView .Fields.Add(bf);

It's necessary for the AutoCompleteExtender :

AutoCompleteExtender ace = new AutoCompleteExtender();
ace.ID = "ace" + sField;
//ace.TargetControlID = "detV$ctl" + xxxxx
ace.TargetControlID = sField;
ace.ServiceMethod = "GetCompletionList";
ace.ServicePath = "wsLkAutoComplete.asmx";
ace.MinimumPrefixLength = 2;
ace.EnableCaching = true;
ace.CompletionInterval = 300;

Any idea ? I can't find this anywhere...

Best Regards

Do you need to be doing this dynamically? If so, have you tried creating a templatefield, the adding a label to the item template of the template field, and a textbox to the edit template field. At this point you will have the textbox so you can use the TextBox1.ClientId property to get its client id. This should return the clientid from within its container.


hello, thank you for replying !

I already tried creating a templatefield, but didn't liked it...

I wanted to use the boundfield, so that it could generate the right controls by itself for the data,

and not to write the needed logic for insert-update-delete-etc.etc.

Using templatefield, would be like making it by hand...

best regards


Hi Kaliban555,

Ajax Control Toolkit's TargetControl should be a server side control. As far as I know, if you use BoundField , we cannot generate a server side control(not html code) and bind it to the Extender. BoundField is not a container indeed. So I think in this situation, TemplateField is a better choice.

I hope this help.

Best regards,

Jonathan.

DetailsView & ObjectDataSource: Cancel Insert but Retain User Input

Hi,

I need to cancel an insert operation during a DetailsView/ObjectDataSource insert event, and display to the user the same insert page with their previously entered values. For example, after a server side input validation the user may need to modify some of the values they entered.

Canceling insert is easy in the ObjectDataSource.Inserting event handler: e.Cancel = true;

However, this cancels insert mode and the values the user input are lost. The ObjectDataSource.Inserting event handler has access to the input parameters, which contain the values the user has entered. It is possible to put the DetailsView object back into insert mode: DetailsView1.DefaultMode = DetailsViewMode.Insert; but I don't know how to programatically assign the user values to the fields, since I do not know how to get a handle to the field.

How does one retain the user input values in insert mode when canceling an inserting event in the DetailsView/ObjectDataSource programming model?

Thanks,

Paul

You should validate the input values in the DetailsView ItemInserting event, rather than in the ObjectDataSource Inserting event. In such case the input values will be retained though you cancel the inserting event

protected void DetailsView1_ItemInserting (object sender, DetailsViewInsertEventArgs e)
{
// validate
e.Cancel = true;
}

Thanks

-Mark post(s) as "Answer" that helped you

DetailsView & Ajax Calender

Hi there,

I have a textbox within a DetailsView called txtDate, What I am trying to do is use the ajax extension to show a calender however whenever I try run the page I get an error telling me txtDate can not be found.

What do I need to do to enable this?


Any help would be great.

Thanks once again.


Shane

Can anyone point me in the right direction?

Designer rendering error for UpdateProgress control, cant find ScriptManager

My page includes a scriptmanager right at the top, as always. I have a detailsview that includes a couple of TemplateFields that contain in the ItemTemplate, updatePanels. Each updatePanel contains a label, button, and UpdateProgress control. In the design mode the designer gives the error for the detailsView, "There was an error rendering a control. The Control with the ID 'UpdateProgress1' requires a ScriptManager on the page. The Script must appear before any controls that need it."

Here is an example of the Template field:

<asp:TemplateField HeaderText="BadLogistics"> <ItemTemplate> <asp:UpdatePanel ID="UpdatePanelBL" runat="server"> <ContentTemplate> <asp:Button ID="BLButton" runat="server" OnClick="BLButton_Click" Text="Get number of Files" /> <asp:UpdateProgress ID="UpdateProgressBL" runat="server" AssociatedUpdatePanelID="UpdatePanelBL" DisplayAfter="1"> <ProgressTemplate> <asp:Image ID="ImageBL" runat="server" ImageUrl="~/images/ajax-loader.gif" /> </ProgressTemplate> </asp:UpdateProgress> <asp:Label ID="BLLabel" runat="server"></asp:Label> </ContentTemplate> </asp:UpdatePanel> </ItemTemplate> <HeaderTemplate>Bad Logistics Status PDSF Files in the last <asp:Label ID="BadLogisticsMins" runat="server" ForeColor="Red"></asp:Label> Minutes </HeaderTemplate> </asp:TemplateField>

Am I doing anything wrong here? I'm pretty new to Ajax. The website runs fine, but the designer just shows this error instead of the fields. How can I fix this? Is this an unsupported use?

Just to be clear, the script manager is the first control inside the form, and no master pages are being used. I don't understand why it can't find the ScriptManager that is clearly on the page right above the detailsview. Any Ideas?

Thanks for the help in advance!

Hi BenderM,

You mention the error states that the updateprogress ID is UpdateProgress1, but your sample code shows it to be calledUpdateProgressBL

Please include the CODE containing the UpdateProgress control with the ID UpdateProgress1.

Thanks,

wil


Sorry about that, the error stats UpdateProgressPP instead of UpdateProgress1. Here is the code containing that UpdateProgressPP, it is alost exactly the same as UpdateProgressBL:

<asp:TemplateField> <ItemTemplate> <asp:UpdatePanel ID="UpdatePanelPP" runat="server"> <ContentTemplate> <asp:Button ID="PollpathButton" runat="server" OnClick="PollpathButton_Click" Text="Get number of Files" /> <asp:UpdateProgress ID="UpdateProgressPP" runat="server" AssociatedUpdatePanelID="UpdatePanelPP" DisplayAfter="1"> <ProgressTemplate> <asp:Image ID="ImagePP" runat="server" ImageUrl="~/images/ajax-loader.gif" /> </ProgressTemplate> </asp:UpdateProgress> <asp:Label ID="PollpathLabel" runat="server"></asp:Label>  </ContentTemplate> </asp:UpdatePanel> </ItemTemplate> <HeaderTemplate> <div style="width:200px"> # of files in Pollpath, created in the last <asp:Label ID="PollpathMins" runat="server" ForeColor="Red"></asp:Label> Minutes </div> </HeaderTemplate> </asp:TemplateField>
I hope that helps.

hey benderm,

I cant see where the problem is. I dont want you to do this until you are certain all other options have been tried, but I helped someone a couple days ago that had a problem where something using Ajax just didn't make any sense and he fixed it by downloading the latest build of Ajax 1.0 (I think he said the latest was only a couple months old).

That or reinstall VS servicepack 1!Embarrassed

Sorry I nothing else for you.


I see this problem when I use master pages....Huh?

I am using the newest build of ajax.

i reinstalled Vs2005 SP1 and still am getting the designer message


Did you ever solve this problem? I am having the same issue.


Anyone? Anyone? this problem still persists with VS2008 RTM (.NET2.0)