I am having an issue Finding a few controls. They are in a FormView.
<asp:Panel ID="Panel5" runat="server">
<table cellpadding="3" cellspacing="2" class="formInnerTable">
<tr>
<td>
<asp:UpdatePanel ID="UpdatePanel4" runat="server">
<Triggers >
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="bttnSavee" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:HiddenField ID="HidVendor" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:FormView ID = "FVedit" DefaultMode = "Edit" runat = "server"
DataSourceID="SqlDataSource5">
<EditItemTemplate>
<table>
<tr>
<td align="center" colspan = "2">
<font color="blue" size="Medium">
<asp:Label ID="Label11" runat="server" Text='<%# Bind("data") %>'></asp:Label>(
<asp:Label ID="TextBox3" ForeColor = "blue" runat="server" Text='<%# Bind("data") %>'></asp:Label>)
</font>
<br /><br>
</td>
</tr>
<tr align="left">
<td align="right">
<asp:Label ID="Label2" runat="server" Text="As2 ID: "></asp:Label>
</td>
<td align="left">
<asp:TextBox ID="txtAs2IDe" runat="server" MaxLength = "30" Text='<%# Bind("data") %>'></asp:TextBox>
<asp:RequiredFieldValidator
ID="RFVe" Display="Dynamic" ControlToValidate = "txtAs2IDe" runat="server" ErrorMessage="You must Insert a Production AS2 Identifier."> </asp:RequiredFieldValidator>
<ajaxToolkit:ValidatorCalloutExtender ID="ValidatorCalloutExtender1e" TargetControlID="RFVe" HighlightCssClass="validatorCalloutHighlight" runat="server">
</ajaxToolkit:ValidatorCalloutExtender>
</td>
**I want access to all those controls in FVedit ** In the code behind I have access to FVedit, but i noticed that the controls count for this formview is only one when there are many controls in it.
How can i get access to those controls in code?
The "one" control, is likely to be something like the template - I'm fairly (but not 100%) sure that you'll have to get the "TemplateItem" (I'm not entirely sure what the name of this control would be).
Alternatively, use (TextBox)FVedit.FindControl("txtAs2IDe") to get the controls in there - this seems to be quite a common approach
I can get access in the Formview's Databound.
That's how you do it.
Related
I have a repeater that displays products, and the footer is input fields where you can choose a product from a db and add it to the repeater. The first field of the add line in the footer is a RadComboBox (with product names) and I want to update the other input fields with info from the db when SelectedIndexChanged for that combobox.
The problem is finding those other controls in my code-behind function.
protected void ProductSelected(Object source, EventArgs e)
{
RadComboBox temp = (RadComboBox)source;
Product p = session.Query<Product>()
.Where(x => x.Name == temp.SelectedItem.Text)
.FirstOrDefault();
var repParent = temp.Parent;
//var repParent = ((UpdatePanel)temp.NamingContainer.FindControl("UpdateHardwareLine")).ContentTemplateContainer;
((TextBox)repParent.FindControl("AddPartNumber")).Text = p.PartNumber;
((TextBox)repParent.FindControl("AddPartCost")).Text = p.Cost.ToString();
((TextBox)repParent.FindControl("AddUnitPrice")).Text = p.Price.ToString();
((TextBox)repParent.FindControl("AddQuantity")).Text = p.DefaultQuantity.ToString();
}
I've tried this 2 ways. At first I put the UpdatePanel in the footer of the repeater, and I changed repParent to the commented version. This produced some really weird results where it updated the input fields, but now they're above my entire repeater o_0?
Then I pulled the updatepanel out of the repeater, and it updates, but it refreshes the entire page. I would settle for just updating the footer, but it'd be neat to get those add/delete buttons working in the same update panel. How should I go about setting this up so it just refreshes for whats in this well?
as requested;
<asp:Repeater ID="repHW" runat="server" OnItemCommand="rep_ItemCommand">
<HeaderTemplate>
<table style="width:100%; padding-bottom:10px" id="HWtable">
<tr style="font-weight: bold"><td>Product</td><td>Part Number</td><td>Cost</td><td>Unit Price</td><td>Quantity</td><td>Price</td><td>Delete</td></tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<asp:HiddenField ID="Category" Value="Hardware" runat="server"/>
<td><asp:Label ID="Product" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Product.Name") %>' /></td> <!--TODO: make this clickable to edit -->
<td><asp:Label ID="PartNumber" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Product.PartNumber") %>' /></td>
<td><asp:Label ID="PartCost" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Product.Cost") %>' /></td>
<td><asp:Label ID="UnitPrice" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Product.Price") %>' /></td>
<td><asp:Label ID="Quantity" runat="server" Text='<%# Eval("Quantity") %>' /></td>
<td><asp:Label ID="Price" runat="server" Text='<%# Eval("Total") %>' /></td>
<td><asp:Button class="btn btn-danger" ID="DeleteHardware" runat="server" Text="Delete" CommandName="Delete" CommandArgument='<%# Container.ItemIndex %>'/></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<asp:UpdatePanel ID="UpdateHardwareLine" updatemode="Conditional" runat="server" ChildrenAsTriggers="true">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="AddProduct" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<asp:HiddenField ID="AddCategory" Value="Hardware" runat="server"/>
<td><telerik:RadComboBox runat="server" ID="AddProduct" ClientIDMode="static" Filter="Contains" EnableLoadOnDemand="true" AutoPostBack="true" OnSelectedIndexChanged="ProductSelected" OnDataBinding="LoadProductsByCategory"/></td>
<td><asp:TextBox runat="server" ID="AddPartNumber" ClientIDMode="static"/></td>
<td><asp:TextBox runat="server" ID="AddPartCost" ClientIDMode="static"/></td>
<td><asp:TextBox runat="server" ID="AddUnitPrice" ClientIDMode="static"/></td>
<td><asp:TextBox runat="server" ID="AddQuantity" ClientIDMode="static"/></td>
<td><asp:Button class="btn btn-success" ID="AddHardware" runat="server" Text="Add" CommandName="Add" CommandArgument='<%# DataBinder.Eval(Container, "ItemIndex") %>' onClientClick="return EmptyFieldCheck('Hardware');"/></td>
</ContentTemplate>
</asp:UpdatePanel>
</tr></table>
</FooterTemplate>
</asp:Repeater>
You could display the content of the footer in a separate table. Something like this:
<FooterTemplate>
<tr>
<td colspan="7">
<asp:UpdatePanel ID="UpdateHardwareLine" updatemode="Conditional" runat="server" ChildrenAsTriggers="true">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="AddProduct" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<table style="width:100%;">
<tr>
<asp:HiddenField ID="AddCategory" Value="Hardware" runat="server"/>
<td><telerik:RadComboBox runat="server" ID="AddProduct" ClientIDMode="static" Filter="Contains" EnableLoadOnDemand="true" AutoPostBack="true" OnSelectedIndexChanged="ProductSelected" OnDataBinding="LoadProductsByCategory"/></td>
...
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</FooterTemplate>
The challenge would be to get that inner table aligned properly with the outer one. You would probably need to set CellPadding="0" and CellSpacing="0" for both tables as a first step.
I am facing problems while using the ListView Control in asp.net
I used two buttons links in a ListView ItemTemplate. For both buttons, I used Command Name and Command Argument. But first one is working fine and the second one is giving errors. I.e.
System.InvalidOperationException: Insert can only be called on an insert item. Ensure only the InsertTemplate has a button with CommandName=Insert.
If I want to add the InsertTemplate, where do we have to place it?
I am copying my code. Please help me.
Design View :
<asp:ListView ID="ListView1" runat="server" GroupPlaceholderID="groupPlaceHolder1" ItemPlaceholderID="itemPlaceHolder1" GroupItemCount="2" OnPagePropertiesChanging="ListView1_PagePropertiesChanging" DataKeyNames="InventoryID" OnItemCommand="ListView1_ItemCommand">
<LayoutTemplate>
<table width="100%">
<tr style="background-color:lightblue;color:blue;text-align:center;font-size:25px;font-weight:bold">
<td colspan="2">Available Books</td>
</tr>
<asp:PlaceHolder ID="groupPlaceHolder1" runat="server"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr>
<asp:PlaceHolder ID="itemPlaceHolder1" runat="server"></asp:PlaceHolder>
</tr>
</GroupTemplate>
<ItemTemplate>
<td>
<table cellpadding="2" cellspacing="0" border="1" style="width:100%;height:100px; border:dashed 1px #04AFEF;background-color:#B0E2F5">
<tr>
<td>
<asp:Button ID="btnReview" runat="server" Text="Review" CommandName="Select" CommandArgument='<%# Eval("InventoryID") %>'/>
</td>
<td></td>
<td>
<asp:Button ID="btnAddToCart" runat="server" Text="Add To Cart" CommandName="Insert" CommandArgument='<%# Eval("InventoryID") %>' />
</td>
</tr>
</table>
</td>
</ItemTemplate>
</asp:ListView>
Well you can insert a InsertItemTemplate like here :
<InsertItemTemplate>
<tr style="background-color:#D3D3D3">
<td valign="top">
<asp:Label runat="server" ID="FirstNameLabel"
AssociatedControlID="FirstNameTextBox" Text="First Name"/>
<asp:TextBox ID="FirstNameTextBox" runat="server"
Text='<%#Bind("FirstName") %>' /><br />
<asp:Label runat="server" ID="LastNameLabel"
AssociatedControlID="LastNameTextBox" Text="Last Name" />
<asp:TextBox ID="LastNameTextBox" runat="server"
Text='<%#Bind("LastName") %>' /><br />
<asp:Label runat="server" ID="EmailLabel"
AssociatedControlID="EmailTextBox" Text="E-mail" />
<asp:TextBox ID="EmailTextBox" runat="server"
Text='<%#Bind("EmailAddress") %>' />
</td>
<td>
<asp:LinkButton ID="InsertButton" runat="server"
CommandName="Insert" Text="Insert" />
</td>
</tr>
</InsertItemTemplate>
Used From : https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.insertitemtemplate(v=vs.110).aspx
I am created a page with update panel and used Asp.net validation controls to be
validated the page is making an issue is "i am straightly going to submit the page
and page gets validated properly then, i am going to click/select any controls on
the page is not get post back"
The below code i am used
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<div id="divMyDataManualEntry" runat="server">
<table cellpadding="3" cellspacing="0" border="0" width="100%">
<td style="width: 5%;" valign="top">
<asp:Label ID="lblGeo" Font-Bold="true" runat="server" Text="Geography"></asp:Label><span
class="redtext">*</span>
</td>
<td valign="top" style="width: 15%">
<asp:DropDownList ID="ddlgeo" TabIndex="1" runat="server" CssClass="textbox" Width="100%"
OnSelectedIndexChanged="ddlgeo_SelectedIndexChanged" AutoPostBack="true">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="ddlgeo"
ValidationGroup="Submit" InitialValue="-1" ErrorMessage="Select Geography"></asp:RequiredFieldValidator>
</td>
</tr> </table>
<table width="100%" id="BtnContainer" runat="server">
<tr>
<td align="center">
<asp:Button ID="btnSubmit" runat="server" OnClientClick="javascript:return IsValidated();"
ValidationGroup="Submit" CssClass="Keybutton" TabIndex="14" Text="Submit" OnClick="btnSubmit_Click" />
<asp:Button ID="btnreset" runat="server" Text="Reset" CssClass="Keybutton" TabIndex="15"
OnClick="btnReset_click" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel runat="server" ID="UpdatePanel" UpdateMode="Always">
<ContentTemplate>
<asp:ListView ID="EditModeListView" runat="server" DataSourceID="DataSourceWrite">
<itemtemplate>
<tr class="cat" onclick="return ApplyTRToggle(this);">
<td colspan="5"><img src="/_layouts/images/COLLAPSE.GIF" class="toggle-img"/> <%# Eval("Cat.CategoryName")%></td>
</tr>
<asp:ListView ID="SubListView" runat="server" DataSource='<%# Eval("Blocks") %>' >
<ItemTemplate>
<tr class="sec" onclick="return ApplyTRToggle(this);">
<td></td>
<td><img src="/images/COLLAPSE.GIF" /><%# Eval("Block.CategoryName")%> </td>
<td></td>
<td><%# Eval("StringFormat") != null ? String.Format(Eval("StringFormat").ToString(), Eval("BlockSum")):Eval("BlockSum") %></td>
<td>
<asp:ListView ID="SuberListView" runat="server" DataSource='<%# Eval("Crits") %>' >
<ItemTemplate>
<tr>
<asp:HiddenField ID="Identifier" runat="server" Value='<%# DataBinder.Eval(Container.DataItem, "ValueID")%>' />
<td></td>
<td><%# Eval("Crit.CategoryName")%></td>
<td><%# Eval("CritUnit")%></td>
<td>
<asp:HiddenField runat="server" ID="IsDecimalController" Value='<%# DataBinder.Eval(Container.DataItem, "IsDecimal")%>' />
<asp:TextBox runat="server" ID="ValueControl" Text='<%# DataBinder.Eval(Container.DataItem, "CritSum")%>' MaxLength="12"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="ErrorMSG" ValidationGroup="NumbersValidation" ControlToValidate="ValueControl" Display="Dynamic"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ValidationExpression='<%# Const.FLOAT_DIGITALS%>' ValidationGroup="NumbersValidation" ErrorMessage="ErrorMSGG" ControlToValidate="ValueControl" Display="Dynamic" />
</td>
<td><%# DataBinder.Eval(Container.DataItem ,"Crit.Comment")%></td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<div ID="itemPlaceholder" runat="server"></div>
</LayoutTemplate>
</asp:ListView>
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<tr ID="itemPlaceholder" runat="server"></tr>
</LayoutTemplate>
</asp:ListView>
</itemtemplate>
<layouttemplate>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<div runat="server" ID="itemPlaceholder">
</div>
</table>
<div class="indicators-toolbar">
<asp:Button runat="server" ID="saveButton" Text="Save" ValidationGroup="NumbersValidation" CausesValidation="true" onclick="saveButton_Click"/>
<asp:Button runat="server" ID="cancelButton" Text="Cancel" CssClass="ms-ButtonHeightWidth" CausesValidation="false" onclick="cancelButton_Click"/>
</div>
</layouttemplate>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
that's in my usercontrol. the problem is when type no valid text or leave empty in <asp:TextBox runat="server" ID="ValueControl" Text='<%# DataBinder.Eval(Container.DataItem, "CritSum")%>' MaxLength="12"></asp:TextBox> fires requiredfield validator and shows error text.. then press submit button, nothing happens, but then after typing correct text in textboxes and no validator fires submit button does NOT work. How to solve the problem
while click on button fire a trigger in ajax.....
it may help to you
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="imgbtnSubmit" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
I'm an asp.net newbie. Basically, I have a DropDownList within and EditItemTemplate within a ListView. When a new item is selected in the drop down, the user would like to NOT have to click the LinkButton for update, but have the update happen automatically. I've experimented with the OnSelectedIndexChanged="ddlrank_itemChanged" using code behind, as well as OnChange="MyFoo()" in javascript, but the details of what to do are beyound me.
I hope I am including the code sample correctly. Any suggestions will be greatly appreciated. Thanks.
<asp:ListView ID="ListView1" runat="server" DataKeyNames="rankingID" DataSourceID="SqlDataSource1" OnItemUpdated="ListView1_Item_Updated">
<LayoutTemplate>
<table cellpadding="2" width="640px" border="1" runat="server" id="tblRankings">
<tr id="Tr1" runat="server">
<th id="Th1" runat="server">Action</th>
<th id="Th3" runat="server">Rank</th>
<th id="Th4" runat="server">Committee name</th>
<th id="Th5" runat="server">Committee type</th>
</tr>
<tr runat="server" id="itemPlaceholder" />
</table>
<asp:DataPager runat="server" ID="RankingDataPager" PageSize="100">
<Fields>
<asp:NextPreviousPagerField ShowFirstPageButton="true" ShowLastPageButton="true"
FirstPageText="|<< " LastPageText=" >>|"
NextPageText=" > " PreviousPageText=" < " />
</Fields>
</asp:DataPager>
</LayoutTemplate>
<ItemTemplate >
<tr id="Tr2" runat="server">
<td>
<asp:LinkButton ID="EditButton" runat="Server" Text="Edit" CommandName="Edit" />
</td>
<td valign="top">
<asp:Label ID="RankLabel" runat="Server" Text='<%#Eval("rank") %>' />
</td>
<td valign="top">
<asp:Label ID="CommitteeNameLabel" runat="Server" Text='<%#Eval("committeename") %>' />
</td>
<td valign="top">
<asp:Label ID="CommitteeTypeLabel" runat="Server" Text='<%#Eval("committeetype") %>' />
</td>
</tr>
</ItemTemplate>
<EditItemTemplate >
<tr style="background-color: #ADD8E6">
<td>
<asp:LinkButton ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
<asp:LinkButton ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
<td>
<asp:DropDownList ID="ddlrank"
DataSourceID="sdsrank"
DataValueField="vchvalue"
DataTextField="vchvalue"
OnSelectedIndexChanged="ddlrank_itemChanged"
OnChange="MyFoo()"
SelectedValue='<%# Bind("rank") %>' runat="server" >
</asp:DropDownList>
</td>
<td>
<asp:TextBox ID="CommitteeNameTextBox" runat="server" Enabled="false" ReadOnly="true" Text='<%#Bind("committeename") %>'
MaxLength="200" /><br />
</td>
<td>
<asp:TextBox ID="CommitteeTypeTextBox" runat="server" Enabled="false" ReadOnly="true" Text='<%#Bind("committeetype") %>'
MaxLength="20" /><br />
</td>
</tr>
</EditItemTemplate>
</asp:ListView>
I think you are missing AutoPostBack="true" on your dropdownlist property. Hope it helps.
You're headed in the right direction. You can use "OnSelectedIndexChanged", or you can create a function in your codebehind page that handles the SelectedIndexChanged event. Either way, when the user makes a selection from the dropdown, you get a postback and that function is executed. In the function you can do whatever you want. In a case like this that might mean checking what the selected value is and setting other values on the screen based on the new selection. When the function exits, a new screen is sent to the user's browser with any updated data.
Thanks for the replies, they helped direct and refine my internet searching!
I finally found a simple solution.
It just requires two lines of code in the OnSelectedIndexChanged code-behind function defined on the dropdownlist:
protected void ddlrank_itemChanged(object sender, EventArgs e)
{
ListViewDataItem item = (ListViewDataItem)((DropDownList)sender).Parent;
ListView1.UpdateItem(item.DisplayIndex, false);
}