473,657 Members | 2,654 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Selecting item in DataList

Hi

asp.net 2.0

My webpage has a DataList containing a TemplateField (ImageButton). When the
ImageButton is clicked it becomes the selected ImageButton. This works okay
as it is. But this isn't an ideal solution, because CommandArgument in this
solution will contain a counter (first element have value 0, then 1 etc).
Instead I think it would be better to have some kind of Id from Car object
stored in the CommandArgument so I easier could access to the id of the
selected object. But then I don't know how to set the SelectedIndex when a
ImageButton is clicked..... below is some of my code...

protected void imgThumbnail_Co mmand(object sender, CommandEventArg s e)
{
dlThumbnails.Se lectedIndex = Convert.ToInt32 (e.CommandArgum ent);
}

protected void dlThumbnails_It emDataBound(obj ect sender,
DataListItemEve ntArgs e)
{

if (e.Item.ItemTyp e == ListItemType.It em ||
e.Item.ItemType == ListItemType.Al ternatingItem ||
e.Item.ItemType == ListItemType.Se lectedItem )
{
Car car = (Car)e.Item.Dat aItem;

ImageButton img =
(ImageButton)e. Item.FindContro l("imgThumbnail ");
img.CommandArgu ment = _count.ToString ();
_count++; //_count is a class variable, int
//some more logic here
}

}

any suggestions?
Nov 3 '08 #1
0 1082

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
9114
by: Umut K. | last post by:
Hi all, I've a DataList control and it's DataBound by a SqlDataReader... The Reader returns say 3 records and as expected the datalist shows 3 rows. What i want to do is to add another extra Record (which is not neccesarily a database record..) but it'll be shown up as an ordinary item in the datalist rendered as an Item or AlternatingItem ... Is there a way to do this? Thanks
2
3945
by: Kel Good | last post by:
Hello, I am binding a custom IList object to a DataList that I am using for a web menu. The items in the custom IList have properties that allow me to dynamically define how my menu behaves. My binding syntax is standard: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load MenuItems.DataSource = GetMyCustomIList MenuItems.DataBind()
3
9882
by: Stimp | last post by:
I have a datalist that outputs a link to a picture in each ItemTemplate: e.g. <asp:DataList id="DataList1" ...etc> <ItemTemplate> <a href='Pic.aspx?pic=somenumber'>picture</a> </ItemTemplate> <asp:DataList> What I want to do is set the "pic=somenumber" querystring value
5
13386
by: Patrick.O.Ige | last post by:
I'm binding a CheckBoxlist below in the ItemDataBound(the CheckBoxList is in a Datalist) By doing "li.Selected = True" i can see all the checkBoxes are selected. But what i want is to be able to get a Boolean value TRUE or FALSE when a checkBox is selected. When the checkBoxList was out of the DataList i used "OnSelectedIndexChanged" and it was returning what i wanted but if its in a
2
3642
by: Fabiano | last post by:
Please, i need to hide a Item(Collumn) of a DataList that is inside of another DataList based on some data that i my database returns. For a sample i created the code above, but it doesn't work. I tryed the visible property, everything. Tks in adv. Fabiano
2
2045
by: Mike Kelly | last post by:
Hi. I have a data table where rows are grouped according to a certain criteria and I want to be able to display all the rows that belong to the same group together on the screen. In addition, I want to provide the user with a way of selecting a single group. A radio button is the obvious choice, but other suggestions will be welcome. For example, the following is what I want to build:
16
12140
by: Vikas Kumar | last post by:
i am selectin some data from database and through reader showing it in datalist as above now for radio buttons i have single column which returns 1,2,3 and according to that i want one of above radio button to be preselected in this datalist how can i do that doing something like this but this gives error "The type or namespace name 'rdbtn' could not be found (are you missing a using directive or an assembly reference?)" as its in datalist
0
933
by: Gert | last post by:
Hi, I am struggling with something relative new to me. Using a simple datalist and a sqldatasource I am showing records in a 2 column wide table. Very easy, no real code so far. No I like to put a radiobutton in the itemtemplate (or where else) so let the user choose one of the items. Please help me,
1
1696
by: lucaslyana | last post by:
I have a datalist with multiple controls in the itemtemplate which can be selected. For example, a button can be clicked to vote on a topic, and upon selection it increments by 1. If I click on a second item from the same row in the datalist, such as another vote button, or a hyperlink, the row disappears and shows as a blank in the data list. I traced the second click and found that the ItemCommand section is never called for the...
0
8306
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
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...
0
7327
agi2029
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...
0
4152
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...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1615
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.