I have a ListView. At the moment I have to click in a Button to show the InsertItemTemplate, as shown below.
Default.aspx:
<LayoutTemplate>
<ul>
<asp:PlaceHolder ID="ItemPlaceHolder" runat="server" />
</ul>
<asp:Button ID="New" Text='New' CommandName="Create" OnClick="Novo_Click" runat="server" />
</LayoutTemplate>
Default.aspx.cs:
protected void Novo_Click(object sender, EventArgs e)
{
ListViewID.InsertItemPosition = InsertItemPosition.LastItem;
}
How can I have the InsertItemTemplace visible without needing to click a button?
Just add that line in the ListView declaration: InsertItemPosition="LastItem" to show, the template, at the end or
InsertItemPosition="FirstItem" to show, the template, in the top
The default is InsertItemPosition.None, which indicates that the InsertItemTemplate content will not be rendered by the ListView control.
<asp:ListView ID="ContactsListView"
DataSourceID="ContactsDataSource"
DataKeyNames="ContactID"
OnItemInserted="ContactsListView_ItemInserted"
InsertItemPosition="LastItem"
runat="server">
...
</asp:ListView>
Related
I have an aspx page (say MyPage.aspx) where a part of it has the following structure -
<asp:DataList ... >
<HeaderTemplate>
...
</HeaderTemplate>
<ItemTemplate>
<asp:Table ID="table" runat="server">
<asp:TableRow ... >
<asp:TableCell ... >
<asp:ImageButton ID="btnToggle" OnClick="ToggleVisibility" ... >
</asp:TableCell>
...
</asp:TableRow>
</asp:Table>
<asp:DataGrid ... >
</asp:DataGrid>
<asp:Panel ID="panel" runat="server" ...>
<asp:Button ID="button1" runat="server" ...>
<asp:Button ID="button2" runat="server" ...>
</asp:Panel>
</ItemTemplate>
<AlternatingItemTemplate>
...
</AlternatingItemTemplate>
</asp:DataList>
What I am trying to do is that whenever btnToggle is clicked, it toggles visibility of panel. I'm getting the panel in ToggleVisibility() like this -
Dim panelToggle As Panel = sender.Parent.Parent.Parent.Parent.Controls(5)
In this function I'm able to change its Visible property, but its visibility doesn't change on the rendered HTML page (checking through browser).
I'm unable to figure out why is that. Kindly, help.
Thanks.
Add the OnItemCommand event to the DataList that handles the button click. You don't need to add the OnClick event to the button itself anymore.
<asp:DataList ID="DataList1" runat="server" OnItemCommand="DataList1_ItemCommand">
<ItemTemplate>
<asp:Button ID="btnToggle" runat="server" Text="Button" />
<asp:Panel ID="panel" runat="server">
Panel content.
</asp:Panel>
</ItemTemplate>
</asp:DataList>
Then in code behind
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
//find the panel in the datalist item object and cast it back to a panel
Panel panel = e.Item.FindControl("panel") as Panel;
//you can now access it's properties
panel.Visible = false;
}
VB
Protected Sub DataList1_ItemCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs)
'find the panel in the datalist item object and cast it back to a panel
Dim panel As Panel = CType(e.Item.FindControl("panel"),Panel)
'you can now access it's properties
panel.Visible = false
End Sub
I have a problem.
I've written this code:
<asp:ListView ID="ListComment" runat="server">
<LayoutTemplate>
<asp:PlaceHolder ID="itemPlaceHolder" runat="server"></asp:PlaceHolder>
</LayoutTemplate>
<ItemTemplate>
<div class="CommentArea" id='Comment<%#Eval("Id")%>'>
<div class="UserDate">
<span class="font07em fontunderline"><b>Inviato da: </b></span><span class="font07em"><b><%#Eval("Autore") %></b></span><span class="font07em fontunderline"><b> alle <%#Eval("Orario", "{0:hh':'mm}") %></b></span>
</div>
<div class="LikeDontLike">
<span class="font07em"><b>
<asp:LinkButton runat="server" ID="Like" CommandArgument='<%#Eval("Id")%>' OnClick="Mipiace_Click" >Like</asp:LinkButton>: <%#Eval("Mipiace") %> /
<asp:LinkButton runat="server" ID="DontLike" CommandArgument='<%#Eval("Id")%>' OnClick="Nonmipiace_Click" >Don't Like</asp:LinkButton>: <%#Eval("Nonmipiace") %></b></span>
</div>
<div class="UserComment">
<span class="font07em"><%#Eval("Commento") %></span>
</div>
</div>
</ItemTemplate>
</asp:ListView>
<asp:DataPager runat="server" ID="PageComment" PagedControlID="ListComment" PageSize="2">
<Fields>
<asp:NumericPagerField />
</Fields>
</asp:DataPager>
When I made run it and I click on a page of DataPager it doesn't change the view. If I click a second time, it changes.
I'have tried to put the DataPager into the LayoutTemplate, but I have always the same problem. How I can solve it?
Thanks all!
I suppose you're using the page_load event to bind your listview to your datasource.
You need to add a new handle the PagePropertiesChanged event of the listview to rebind your listview again. At the end, your databinding code would be duplicated in the page_load event (not need to check for postback) and in the listview_PagePropertiesChanged event.
You need to add
<asp:ListView ID="ListComment" runat="server" OnPagePropertiesChanging="Listcomment_PagePropertiesChanging">
Then in the codebehind
protected void Listcomment_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
this.ListComment.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
// Rebind your ListComment
}
Is there any way to display listview as another listview's empty data template. I just put it like following. But it wont display the listview or it's emptydata text. only displaying 'empty data first listview' text
<asp:ListView ID="searchResults" runat="server" ItemPlaceholderID="placeholder">
<EmptyDataTemplate>
empty data first listview
<asp:ListView ID="suggestions" runat="server" ItemPlaceholderID="placeholder" DataSource="<%#Model.SearchSuggestions %>">
<EmptyDataTemplate>
empty data second listview</EmptyDataTemplate>
<LayoutTemplate>
<span class="suggestionList">
<asp:PlaceHolder ID="placeholder" runat="server"></asp:PlaceHolder>
</span>
</LayoutTemplate>
<ItemTemplate>
<%# Container.DataItem %>
</ItemTemplate>
<ItemSeparatorTemplate>
,</ItemSeparatorTemplate>
</asp:ListView>
</EmptyDataTemplate>
<LayoutTemplate>
*************
</LayoutTemplate>
</asp:ListView>
I copy and pasted your code and was able to get it to work by manually databinding it in the codebehind. The only modification I made to your aspx code was to remove the reference to the model, to simplify setting it up on my end. I have included my ugly/overly simple test code below.
protected void Page_Load(object sender, EventArgs e)
{
searchResults.DataBind();
searchResults.Controls[0].DataBind();
}
I don't want to show stepname. "Next" and "finish button" is enough for me. How to unvisible these?!
Second question's; after FinishButton's click, I want to redirect first step automatically. How to do?
<asp:Wizard runat="server" ID="MyWizard" OnNextButtonClick="MyWizard_NextButtonClick"
Width="440px" Height="200px" OnFinishButtonClick="MyWizard_FinishButtonClick">
<WizardSteps>
<asp:WizardStep ID="Wizardstep1" runat="server" StepType="auto">
</asp:WizardStep>
<asp:WizardStep ID="Wizardstep2" runat="server" StepType="auto">
</asp:WizardStep>
You can create your custom LayoutTemplate within Wizard control to hide step names. For example:
<LayoutTemplate>
<div>
<asp:PlaceHolder ID="headerPlaceHolder" runat="server" />
</div>
<div>
<asp:PlaceHolder ID="wizardStepPlaceholder" runat="server" />
</div>
<div>
<asp:PlaceHolder ID="navigationPlaceholder" runat="server" />
</div>
</LayoutTemplate>
Remeber that placeholders' id names matter. Placeholer responsible for displaying list of steps that you circled has id sideBarPlaceHolder (and you should not have any placeholder with this id inside LayoutTemlpate)
Second question:
You can have custom navigation template, for example:
<FinishNavigationTemplate>
<asp:Button ID="PreviousButton" runat="server" Text="Previous step" CausesValidation="false" CommandName="MovePrevious" />
<asp:Button ID="FinishButton" runat="server" Text="Finish" CausesValidation="true" CommandName="MoveComplete" OnCLick="FinishButton_Click" />
</FinishNavigationTemplate>
Note that these buttons have fixed CommandName (Wizard control expects this). You can try to use finish button's OnClick event to jump to the first step:
protected void FinishButton_Click(object sender, EventArgs e)
{
yourWizard.ActiveStepIndex = 0;
}
I am using a modal popup that contains a dropdown box. When the dropdown is changed I'm trying to retrieve data and assign it labels also within the modal. I observe the label values being set in the debugger but they do not show in the modal.
Modal/Panel Code:
<asp:Panel ID="pnlUpdate" runat="server" CssClass="modalPopup">
<div>
<asp:UpdatePanel runat="server" ID="upSubnetUpdate" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label runat="server" ID="pnlLblSubnet" CssClass="searchLabel">Subnet:</asp:Label>
<asp:DropDownList runat="server" ID="ddlSubnet" OnSelectedIndexChanged="ddlSubnet_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList><br />
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div>
<asp:Label runat="server" ID="lblIPStartUpdate"></asp:Label>
<asp:Label runat="server" ID="lblIPEndUpdate"></asp:Label>
<asp:Label runat="server" ID="lblGatewayUpdate"></asp:Label>
<asp:Label runat="server" ID="lblSubnetMaskUpdate"></asp:Label>
</div>
</asp:Panel>
Dropdown Code
protected void ddlSubnet_SelectedIndexChanged(object sender, EventArgs e)
{
SubnetInfo si = GetSubnetInfo(ddlSubnet.SelectedItem.Text);
lblIPStartUpdate.Text = si.IP_Start;
lblIPEndUpdate.Text = si.IP_End;
lblGatewayUpdate.Text = si.Gateway;
lblSubnetMaskUpdate.Text = si.Subnet_Mask;
}
I'm not sure if this is a page lifecycle issue or a limitation of the modal popup.
Thanks for the help!
You need to put the DropDown and the labels in an UpdatePanel. The dropdown is in an UpdatePanel, but it cannot update the labels if they're not in an UpdatePanel too.