I have a ListView control with an ItemTemplate, and an EditItemTemplate. By default, the ItemTemplate is rendered; how can I change that? More clearly, on Page_Load, I would like my EditItemTemplate to be the selected template.
<asp:ListView ID="lvExample" runat="server" SelectMethod="GetStuff" UpdateMethod="UpdateStuff">
<EditItemTemplate>
...
</EditItemTemplate>
<EditItemTemplate>
...
</EditItemTemplate>
</asp:ListView>
You can use this approach.
(1) Write your Edit logic/Edit Template in your inside you item template.
(2) Then you can put your ItemTemplate content into another template.
since the default load template is ItemTemplate you get your edit template load first since the content of your itemteplate is your edit template
Related
I need to conditionally set the CssClass for a Template Field - not for the controls in the Template Field - but for the Template Field itself - so that it renders as:
<td class="fred">
or
<td class="jim">
I have been trying things like:
<asp:TemplateField>
<ItemTemplate><%# Eval("ProductName")%></ItemTemplate>
<ItemStyle CssClass='<%# Convert.ToBoolean(Eval("ProductType")) == true ? "fred" : "jim" %>' />
</asp:TemplateField>
and various variations - like trying to set the CssClass dynamically in the tag - but an error is reported that TemplateField and ItemStyle do not support databinding expressions.
How can I dynamically set the CssClass of a TemplateField?
enter code here
I presume that you are using a GridView control... if this is the case, you would apply the styles within the "RowDataBound" event handler.
Waiting for more information...
I have a question on C#. I use the GridView ItemTemplate to add a textbox to a whole column. I add the ID to the drop down list in ItemTemplate. Therefore, the generated ID of drop down list is 'GridViewID_dropdownListID_number' in each row when I launch the project.
However, I cannot set the drop down list to .Visible = true and .Visible = false in .aspx.cs file. I try to type the 'dropdownListID' and 'GridViewID_dropdownListID_number' to 'Page_Load' function. However, it displays the error message which is under light the statement.
'The name 'GridViewID_dropdownListID_0' does not exist in the current content'
Can I set the drop down list visible to true and false in .aspx.cs?
P.S I can retrieve the row number by GridViewRow
you can use FindControl
DropdownLIst tvSeries = (DropdownLIst)tableOfTVSeries.Rows[0].Cells[2].FindControl("tvSeriesTableCategoryDropdownLIst");
Here is an example how to do this in the item template of a repeater -- this is typically how this problem is solved:
<asp:DataList Runat="server" ...>
<ItemTemplate>
<asp:Label runat="Server" Text='<%# Container.DataItem("data") %>'
Visible='<%# Container.DataItem("makevisible") %>'/>
</ItemTemplate>
</asp:DataList>
I am trying to have a collapsible panel inside of a listview item. In the item template, I have a panel, and a collapsible panel extender. In order to set the attributes TargetControlID, CollapseControlID, etc., I need the ClientIDs that are generated after databinding for each of the listview items. Does anyone know how I can set those attributes client-side?
I've tried various things along the lines of the following:
<ItemTemplate>
<asp:Panel ID="ManagingPanel" runat="server">
</asp:Panel>
<asp:CollapsiblePanelExtender runat="server" TargetControlID='<%="ManagingPanel.ClientID" %>' />
</ItemTemplate>
SOLUTION - Turns out you do not need to use the ClientID. The Extender will recognize that its target is inside the same listview item.
<asp:CollapsiblePanelExtender runat="server" TargetControlID="ManagingPanel" />
I have create a custom user control that includes the CollapsiblePanelExtender and every other think that I like to show, a complex html struct, and then I have include this control in the repeater.
The repeater pass the data that I need to render my custom control, and then the custom control render its self in every line of the repeater, and all is working fine.
something like
<asp:Repeater ID="myRepeater" runat="server">
<ItemTemplate>
<uc1:MyCustonControl ID="lPro" runat="server" data="<%#PassData%>" />
</ItemTemplate>
</asp:Repeater>
Turns out you do not need to use the ClientID. The Extender will recognize that its target is inside the same listview item.
<asp:CollapsiblePanelExtender runat="server" TargetControlID="ManagingPanel" />
I currently have a repeater control and inside the itemtemplate I have a usercontrol. This usercontrol renders correctly, but I am trying to assign a dataitem to a property in the repeater control.
<asp:Repeater ID="Repeater1" DataSourceID="EntityDataSource" runat="server">
<ItemTemplate>
<uc1:Request ID="Request1" runat="server" RequestId='<%# Eval("RequestId") %>' />
</ItemTemplate>
RequestId is just an Int32. It just doesn't assign it.
I can put the eval outside of the usercontrol just in the itemtemplate and it correctly outputs the right id.
If I remove the whole eval and just type a number in then it works fine.
Any help appreciated.
[UPDATE] : Issue Solved
I was using an EntityDataSource and this automatically binded to the repeater. It printed out all the information from the database on the screen without any codebehind. But when I put in the code behind Repeater1.DataBind(); it then started to work.
I don't know why, but hey it's solved. It now successfully passes the value through. I imagine it has something to do with the page lifecycle.
If you just bind with repeater collection of int, you need use this:
<uc1:Request ID="Request1" runat="server" RequestId='<%# Container.DataItem %>' />
And don't forget to call DataBind() for repeater or for Page where there is a repeater control.
Are you missing a ' at the end?
change following:
RequestId='<%# Eval("RequestId") %> />
to
RequestId='<%# Eval("RequestId") %>' />
You can implement this by using Repeater control's ItemDataBound event, so that you can set the dynamic property for the control.
I have an AccessDataSource TestSummaryADS. I can easily view the results in a GridView or DropDownList by setting its DataSourceID property.
How do I bind a value from the results TestSummaryADS to the text of a label?
I'm just trying to populate labels on my page with results from the DB entry.
C# or VB.NET answers okay.
If you only have a single record, use a FormView
<asp:FormView ID="FormViewTestSummary" runat="server"
DataSourceID="TestSummaryADS"
DefaultMode="Edit">
<EditItemTemplate>
<fieldset>
<asp:TextBox ID="txtMyText" Text='<%# Bind("ProjectNumber") %>' runat="server" />
Use Repeater control that contains Label controls to display the values you want. Bind your DataSource control to the repeater.
Also you can use TemplateColumn with GridView and add your labels into this template column.
But IMO, Repeater control is simpler to customize your view by templates.