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.
Related
i have a gridview that show comments. i want that if a person likes a comment, press a like button and i increse the sum of likes , but i do not want to connect to database and bind. i want do that using ajax. how can i do that?
here is my code:
<asp:UpdatePanel runat="server" id="UpdatePanel" >
<ContentTemplate>
<asp:GridView ID="grdCommentsForLoginnedUser"
runat="server"
AutoGenerateColumns="False"
Width="100%"
OnRowCommand="grdCommentsForLoginnedUser_RowCommand"
ViewStateMode="Inherit">
<Columns>
<asp:TemplateField >
<ItemTemplate>
<asp:HiddenField ID="hdnCommentID" runat="server"
Value='<%# Bind("CommentID") %>'/>
<table border="2" dir="rtl">
<tr>
<td rowspan="2" style="background-color: #6699FF" width="200px">
<asp:HyperLink ID="lnkCommenterName"
runat="server"
NavigateUrl='<%# Bind("CommenterProfile") %>'
Text='<%# Bind("CommenterName") %>' />
</td>
<td width="700px">
<br />
<asp:Label ID="lblCommentText" runat="server"
Text='<%# Bind("CommentText") %>' />
<br />
</td>
</tr>
<tr>
<td width="700px">
<asp:Label ID="lblPreviousAcceptOrNonAccept" runat="server"
Text='<%# Bind("PersonPreviousAcceptOrNonAccept") %>' />
<asp:LinkButton ID="lnkBtnRemovePreviousAcceptOrNonAccept"
runat="server"
Text='<%# Bind("RemovePersonPreviousAcceptOrNonAccept") %>'
CommandName="RemovePreviousAcceptOrNonAccept"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
<br />
<asp:LinkButton ID="lnkBtnUpRate" runat="server" Text="Like"
Visible='<%# Bind("isLikeAndUnlikeButtonVisible") %>'
CommandName="LikeComment"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
<br />sum of likes
<asp:Label ID="lblCommentLikes" runat="server"
Text='<%# Bind("CommentLikes") %>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
Add a client side onClick javascript to each button. When clicked get the parent td tag and then getElementById("lblCommentLikes") to set the .innerText property of the "lblCommentLikes" span.
+(theTD.getElementById("lblCommentLikes").innerText)+=1;
or
+(theTD.getElementById("lblCommentLikes").innerText)-=1;
Tip: If you are using IE then press F12 to inspect the DOM of a running page
<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);
}
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.
I have two datalists. One works like a menu where you click on a link to fill the othe datalist.
I also have added a next and previous linkbutton to move between the different "pages" so that you do not have to change using the menu datalist.
Now in code behind depending on which values I get from the database I add a RegularExpressionValidator.
This works great until I want to use the next button (or previous for that matter). Even if all the controls that are checked are valid when compared with the RegularExpressionValidator I never get to load the new values.
The next and previous buttons fires the datalist selected index change event and then I check if it is the previous or next button that was clicked.
But the previous and next buttons are numb. They don't even fire the event.
It is like clicking on the background. Nothing happens.
I have chcked the PageIs.Valid and it is true.
Does anyone have a clue what it could be that is causing this behavior?
Thanks in advance!
Some of the texts down there is in Swedish but it shouldn't matter for the code.
rev_checkfieldvalue.ControlToValidate = "tb_detailValue";
switch (iDataTypeId)
{
case 2:
rev_checkfieldvalue.ValidationExpression = #"^\d*[0-9 ]+$";
rev_checkfieldvalue.Text = "Fältet får endast innehålla siffror och mellanslag.";
break;
case 3:
break;
case 4:
break;
case 5:
rev_checkfieldvalue.ValidationExpression = #"\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*";
rev_checkfieldvalue.Text = "Fältet får endast innehålla en e-postadress.";
break;
}
e.Item.Controls.AddAt(32, rev_checkfieldvalue);
<asp:DataList ID="dl_componentInfo" DataKeyField="ComponentId" runat="server" OnItemDataBound="dl_componentInfo_OnItemDataBound" OnItemCommand="dl_componentInfo_OnItemCommand">
<ItemTemplate>
<table>
<tr>
<td colspan="2"><asp:Label ID="lb_componentName" SkinID="lblHeader" runat="server" Text='<%# Eval("ComponentName") %>' /></td>
</tr>
<tr>
<td colspan="2">Fält markerade med * är obligatoriska</td>
</tr>
<tr>
<td> </td>
<td>
<asp:DataList ID="dl_details" OnItemDataBound="dl_details_OnItemDataBound" runat="server">
<ItemTemplate>
<table>
<tr>
<td colspan="2">
<asp:Label ID="lbl_detailName" Text='<%# Eval("DetailName") %>' runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lbl_custDetName" runat="server" />
</td>
<td align="left">
<%--Always hidden values--%>
<asp:Label ID="lbl_detailTypeId" Visible="false" Text='<%# Eval("DetailTypeId") %>' runat="server" />
<asp:Label ID="lbl_detailId" Visible="false" Text='<%# Eval("DetailId") %>' runat="server" />
<asp:Label ID="lbl_dataTypeId" Visible="false" Text='<%# Eval("DataTypeId") %>' runat="server" />
<asp:Label ID="lbl_customerEventValueId" Visible="false" Text='<%# Eval("CustomerEventValueId") %>' runat="server" />
<asp:Label ID="lbl_reqFld" Visible="false" Text='<%# Eval("ReqFld") %>' runat="server" />
<%--Sometimes visible values--%>
<asp:Label ID="lbt_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server" />
<asp:Label ID="lbtb_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server" />
<asp:Label ID="lbth_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server" />
<asp:Label ID="lbc_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server" />
<asp:DropDownList ID="dd_detailValue" Visible="false" runat="server"></asp:DropDownList>
<%--Om det ska gå att markera/avmarkera alla så använd AJAX--%>
<asp:CheckBoxList ID="cbl_detailValue" RepeatDirection="Horizontal" RepeatLayout="flow" Visible="false" runat="server" />
<asp:CheckBox ID="cb_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server" />
<asp:TextBox ID="tb_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server" />
<asp:TextBox ID="ta_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server"></asp:TextBox>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</td>
</tr>
</table>
</ItemTemplate>
<FooterTemplate>
<table width="600">
<tr>
<td>
<asp:LinkButton id="lb_previous" Text="Föregående" CommandName="Previous" runat="server"/>
</td>
<td>
<asp:LinkButton id="lb_next" Text="Nästa" CommandName="Next" runat="server"/>
</td>
</tr>
</table>
</FooterTemplate>
</asp:DataList>
I thought I solved the issue but it just stopped checking.
So for case two you accept any non-empty string of digits and spaces.
Is that your intent?