We have a problem setting, actually resetting, the SelectedItemTem plate
of a DataList control. Below is the ObjectDataSourc e and the DataList
in .ASPX:
<asp:ObjectData Source ID="mySource" runat="server"
SelectMethod="G etStageUsage" TypeName="SomeC ontroller">
</asp:ObjectDataS ource>
<asp:DataList ID="dl" runat="server"
DataSourceID="m ySource" DataKeyField="I D"
OnItemCommand=" dl_ItemCommand" >
<HeaderTemplate >...</HeaderTemplate>
<ItemTemplate>. ..</ItemTemplate>
<SelectedItemTe mplate>...</SelectedItemTem plate>
</asp:DataList>
The ID column has a LinkButton with CommandName="Se lect" set. Now, when
we select a certain row, we want to show the SelectedItemTem plate.
Therefore we used the OnItemCommand event. See code below. We used this
code to check if we need to show or hide the SelectedItemTem plate (ie.
show hide details of that item in the grid). When the details for an
item are already shown, and we select it again, the details must hide
(ie. collapse).
protected void dl_ItemCommand( object source, DataListCommand EventArgs
e)
{
DataList fromList = (DataList)sourc e;
if (e.CommandName == "Select")
{
if (fromList.Selec tedIndex == e.Item.ItemInde x)
{
fromList.Select edIndex = -1;
}
else
{
fromList.Select edIndex = e.Item.ItemInde x;
}
// Rebind the datasource to the datalist
fromList.DataBi nd();
}
}
In this example we check if the CommandName is "Select" and check
to show or hide the SelectedItemTem plate. Now, when we select an item,
the SelectedItem opens (as expected). When we want to hide/collapse the
details we set the SelectedIndex op -1. However, it does not behave as
it "should". The SelectedIndex is set to -1, but on a PostBack it
has the value again of the e.Item.Index. Therefore, it always goes
setting the value to -1, instead of reopening it again (btw; when we
select a other item it opens because the e.Item.Index has another
value).
Finally we found a workaround, and we're not sure if this is the way
to go. We disabled the ViewState of the DataList (dl) in the .ASPX.
Then we changed the ItemCommand event into the code below. Notice that
we changed the check of the fromList to our own ViewState:
protected void dl_ItemCommand( object source, DataListCommand EventArgs
e)
{
DataList fromList = (DataList)sourc e;
if (e.CommandName == "Select")
{
if (Convert.ToInt3 2(ViewState["selectedItemIn dex"]) ==
e.Item.ItemInde x)
{
fromList.Select edIndex = -1
ViewState["selectedItemIn dex"] = -1;
}
else
{
fromList.Select edIndex = e.Item.ItemInde x;
ViewState["selectedItemIn dex"] = e.Item.ItemInde x;
}
// Rebind the datasource to the datalist
fromList.DataBi nd();
}
This does do the trick, but we're not sure if this is a good
practice? Any thoughts?
Thanks,
Jules 1 3161
Hi Jules,
It all looks correct to me.
Setting the SelectedIndex back to -1 and rebinding the list should be
fine. The event should return the correct item index following the
setting of -1. Does anyone know of issues setting the selectedIndex to
-1 and the SelectedItemInd ex in the itemcommand event?
Jonathan
Jules wrote:
We have a problem setting, actually resetting, the SelectedItemTem plate
of a DataList control. Below is the ObjectDataSourc e and the DataList
in .ASPX:
<asp:ObjectData Source ID="mySource" runat="server"
SelectMethod="G etStageUsage" TypeName="SomeC ontroller">
</asp:ObjectDataS ource>
<asp:DataList ID="dl" runat="server"
DataSourceID="m ySource" DataKeyField="I D"
OnItemCommand=" dl_ItemCommand" >
<HeaderTemplate >...</HeaderTemplate>
<ItemTemplate>. ..</ItemTemplate>
<SelectedItemTe mplate>...</SelectedItemTem plate>
</asp:DataList>
The ID column has a LinkButton with CommandName="Se lect" set. Now, when
we select a certain row, we want to show the SelectedItemTem plate.
Therefore we used the OnItemCommand event. See code below. We used this
code to check if we need to show or hide the SelectedItemTem plate (ie.
show hide details of that item in the grid). When the details for an
item are already shown, and we select it again, the details must hide
(ie. collapse).
protected void dl_ItemCommand( object source, DataListCommand EventArgs
e)
{
DataList fromList = (DataList)sourc e;
if (e.CommandName == "Select")
{
if (fromList.Selec tedIndex == e.Item.ItemInde x)
{
fromList.Select edIndex = -1;
}
else
{
fromList.Select edIndex = e.Item.ItemInde x;
}
// Rebind the datasource to the datalist
fromList.DataBi nd();
}
}
In this example we check if the CommandName is "Select" and check
to show or hide the SelectedItemTem plate. Now, when we select an item,
the SelectedItem opens (as expected). When we want to hide/collapse the
details we set the SelectedIndex op -1. However, it does not behave as
it "should". The SelectedIndex is set to -1, but on a PostBack it
has the value again of the e.Item.Index. Therefore, it always goes
setting the value to -1, instead of reopening it again (btw; when we
select a other item it opens because the e.Item.Index has another
value).
Finally we found a workaround, and we're not sure if this is the way
to go. We disabled the ViewState of the DataList (dl) in the .ASPX.
Then we changed the ItemCommand event into the code below. Notice that
we changed the check of the fromList to our own ViewState:
protected void dl_ItemCommand( object source, DataListCommand EventArgs
e)
{
DataList fromList = (DataList)sourc e;
if (e.CommandName == "Select")
{
if (Convert.ToInt3 2(ViewState["selectedItemIn dex"]) ==
e.Item.ItemInde x)
{
fromList.Select edIndex = -1
ViewState["selectedItemIn dex"] = -1;
}
else
{
fromList.Select edIndex = e.Item.ItemInde x;
ViewState["selectedItemIn dex"] = e.Item.ItemInde x;
}
// Rebind the datasource to the datalist
fromList.DataBi nd();
}
This does do the trick, but we're not sure if this is a good
practice? Any thoughts?
Thanks,
Jules
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Barry |
last post by:
Hi,
I have a Datalist inside the ItemTemplate of another DataList. When I
drilldown, I'm not getting any data in either the itemtemplate or
headertemplate of the second DataList. I've confirmed that the
datasource is being populated properly, however the itemdatabound
event is not being fired. Here's some code:
<asp:datalist id="BatchList" runat="server"
repeatdirection="Vertical" headerstyle-cssclass="CategoryHeader"...
|
by: David D. McCrory |
last post by:
This is the second post for this question....please help!!
This is a fairly simple request....I am looking for some help....
I want to set the SelectedIndex of a DataList control to equal a specific
record in the database. What is the easiest way to accomplish this??
Thanks,
David D. McCrory
|
by: V. Jenks |
last post by:
What seems like a simple thing is apparently not so
straightforward?
I have a datalist.
Inside of that datalist is an <itemtemplate> secion which
contains other server controls such as a label, a
radiobuttonlist, etc.
I'm driving myself insane trying to figure out how to get
|
by: mahsa |
last post by:
H
data I'm binding to the DataList is information about products in my product database. Perhaps passed in the QueryString to this page is a ProductID. I might want to make the item in the DataList that has the corresponding ProductID selected. In a similar vein, perhaps I want to have newest product selected by default. How can I acheieve this functionality
actuly i use pagin
<%@ Page language="c#" Codebehind="product.aspx.cs"...
|
by: CVerma |
last post by:
Hi,
I have an embedded datagrid within a datalist. I am not able to
perfrom paging in the datagrid. Any ideas? Here is my code:
Here is my Simplegrid.cs file:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
| |
by: rbutch |
last post by:
i should have included the code in the first post.
sorry.
i've got this working but it returns the 'index' property whereas i'd like the value of what's in the property.i'll include the minimalist of code here
<asp:datalist id="Datalist1" OnItemCommand="getSelected">
<SelectedItemTemplate>
<asp:HyperLink ID="ot_job_id" Runat="server" />
</SelectedItemTemplate>
|
by: Neil Jarman |
last post by:
Hi,
I'm new to this today, and I've got some test code (see below.) The data
loads fine.
I can't understand why any of the events fire. Once the page loads, clicking
on thew button from the ItemTemplate does not fire the OnItemCommand event.
It just fires a page reload - as a postback.
I guess I'm missing something really obvious and important here?
|
by: Isz |
last post by:
PROBLEM:
This problem is related to the postback and handling events correctly.
BACKGROUND:
I have a datalist which acts as a tabbes list with horizontal layout.
This datalist is bound to a strogly typed collection I called
TabCollection which is a collevtion of items called tab. Each tab is as
follows:
|
by: Les Caudle |
last post by:
I have a menu system composed of a DataList nested inside a DataList.
The outer DataList has it's DataSource (composed of a DataSet with two tables
linked by a CategoryPagesRelation Relation) set in the Page_Load.
The inner DataList has its DataSource set in the ascx file as:
<asp:DataList ID="PageList" runat="server" CellPadding="3" CellSpacing="0"
DataSource='<%#...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |