Forms Data Controls :: Setting The Selected Index In A Datalist?

Mar 31, 2010

I have a datalist that holds imagebuttons which all link to images stored in a database. When I click on any of the image buttons the datalist enlarges the chosen picture and manages to dothis as the datalist is binded by the uniqueID of the image in the database. So, when I am looking at the enlarged picture, it would be nice to be able to click 'Next' & 'Prev' link buttons to move onto the next or previous picture without having to return to the datalist in between looking at a different photo.

I have managed to set up methods for clicking on 'next' and 'prev' linkbuttons that will successfully browse back and forth between photos in the datalist but the selected index always starts at 0, i.e the first photo in the datalist. So if I'm viewing the 5th image in the list and press 'next', the first image in the list shows up. I thought just by clicking on an image button would automatically set the selected index but obviously this is not the case. I have read various threads and tutorials on the net and a lot of them point to dlIcons.SelectedIndex = e.Item.ItemIndex; I have tried to put this in the itemDataBound method for my datalist but it changes nothing. And if i try to put that line of code in other messages in the class i get error messages (I'm using Visual Web Developer C#).

its part of a final year project due in 3 weeks and by now I should be writing the report! The code I'm using is pretty huge and spread out between classes but I will include what I think might help illustrate how it all works:

<asp:DataList ID="dlIcons" runat="server" DataKeyField="AttachmentID"
OnItemDataBound="dlIcons_ItemDataBound" ItemStyle-BorderWidth="1px"
RepeatColumns="5" RepeatDirection="Horizontal" CssClass="Icons"
OnSelectedIndexChanged="dlIcons_SelectedIndexChanged">
<AlternatingItemStyle CssClass="AlternatingRowStyle" />
<ItemStyle CssClass="RowStyle" BorderWidth="1px" />
<HeaderStyle CssClass="HeadeBrStyle" />
<FooterStyle CssClass="FooterStyle" />
<SelectedItemStyle CssClass="SelectedRowStyle" />
<ItemTemplate>
<asp:Label ID="lblFilename" runat="server" Font-Size="Small"
Text='<%# Eval("Filename") %>' ></asp:Label>
<br />
<asp:LinkButton runat="server" id="btnDelete" CommandArgument="<%# Bind('AttachmentID') %>"
CommandName="DELETE" Text="Delete" OnClick="btnDelete_Click"
Font-Size="small" CssClass="btnDelete" />
<br />
<asp:ImageButton runat="server" ID="imgBtnFileType" width="120" Height="120"
ImageAlign="right" ImageUrl='<%#"http://localhost:49279/PDFViewer/GetAttachment.ashx?AttachmentID=" &#43; Eval("AttachmentId")&nbsp; %>'
OnClick="imgBtnFileType_Click" BorderWidth="1PX" CssClass="imgBtnFileType"
CommandName="VIEW" CommandArgument="<%# Bind('AttachmentID') %>"/>
<br /><br />
</ItemTemplate>
</asp:DataList>
The CS file:
protected void dlIcons_ItemDataBound(object sender, DataListItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
{
DataRowView drv = e.Item.DataItem as DataRowView;
dlIcons.SelectedIndex = e.Item.ItemIndex;
int attachmentID = (int)drv["AttachmentID"];
string fileType = (string)drv["Type"];
ImageButton imgBtnFileType = e.Item.FindControl("imgBtnFileType") as ImageButton;
string fileName = (string)drv["FileName"];
Label lblFilename = e.Item.FindControl("lblFilename") as Label;
lblFilename.Text = fileName.Length > 12 ? fileName.Substring(0, 10) + ".." : fileName;
}
}
The next and prev link buttons onclick leads to these two methods:
public int nextPic()
{
dlIcons.Items.Equals(dlIcons.SelectedIndex++);
int nextAttach = (int)dlIcons.SelectedValue;
return nextAttach;
}
public int prevPic()
{
dlIcons.Items.Equals(dlIcons.SelectedIndex--);
int prevAttach = (int)dlIcons.SelectedValue;
return prevAttach;
}

these were void methods but i've been stuck on this for hours and have resorted to fiddling with just about everything.

View 6 Replies


Similar Messages:

AJAX :: Datalist With CascadingDropDown - Setting The Selected Index

Dec 21, 2010

I have looked high and low and have not found what I need or found something that could work but it was old and did not work. I have a datalist (in an update panel) that contains 2 dropdownlist (Categories and Sub Categories) being populated by CascadingDropDown. What I want to do is set the selected index of the First one to the value I get from the Database after populating it in the web service. Then based on that I would like to adjust the 2nd dropdown for the new selected index. Here is the ui code

[Code]....

I saw a post about CascadingDropDownProperties using Atlas but I cannot seem to find anything about the AtlasControlKit anymore (is it part of AjaxControlKit?)

View 1 Replies

Forms Data Controls :: Setting The Selected Index / Value In A DropDownList?

Feb 8, 2011

I have a problem in setting the selected index /value in a drop down list. The list is bound by a Linq query and I want to add an item at the top of the list and set it as the selected item.

THis is the code i am using

ListItem li = new ListItem("Select", "", true);
list.DataSource = (from ap in edc.Approvers
where ! ap.approverEmail.Equals("")
orderby ap.approverEmail
select new {ap.approverEmail}).Distinct();
list.DataTextField = "approverEmail";
list.DataValueField = "approverEmail";
list.DataBind();
list.Items.Add(li);
list.Items.FindByText("Select").Selected = true;

The listItem li is the item i want to be first in the list and also selected. Adding this before the databind just loses the item.

View 2 Replies

Forms Data Controls :: Get The Selected Item From The Listbox In The Selected Index Changed Event

Feb 28, 2011

How to get the selected item from the listbox in the selected index changed event. I tried: Label1.Text = ListBox1.SelectedItem.Text; It is giving me object set to null reference.

foreach (ListItem item in ListBox1.Items)
{
if (item.Selected)
{
//lblResults.Text += item.Text + "
";
Label1.Text = item.Text;
}
}

No use, no value coming in to label.

View 5 Replies

C# - AJAX CascadingDropdown - Setting The Selected Index

May 5, 2010

I have a CascadingDropDown on an ASP.NET page. Now, the prompt text is "Select State". (list of states). However, on a different version of this page (ie querystring), i might want to set the selected index to "California" for example. How can i do this? The web service used by the ajax control (ie GetStates) gets invoked at the same time the jquery document.ready function is triggered (ie asynchronously).

So when i try and set the selected index in jquery, the items are not yet bound. Is there a way to attach a handler to the ajax dropdown so that i can set the selected index once the webservice call has completed, and the items are bound?

View 1 Replies

Forms Data Controls :: Getting Selected Key Value From DataList Inside Another Datalist?

Aug 30, 2010

I need to find which Selected Key value that was selected in the ChildDatalist inside the MainDatalist

this is my Html code...for the MainDataList and the nested Childdatalist

[Code]....

View 3 Replies

Forms Data Controls :: Tree View Set Slected Index / Auto Selected Index Change To Tree Node?

Jan 25, 2011

I have two control page in my aspx page. first one left side "tree view",second one right side " form design".Form design will change based on tree view selected index changed.i have 4 level child node(site, master , slave, space). I have seperate forms to each level of node.

cannot update tree node when update the forms. so i reload tree view.

now i need how to auto selected index change to tree node.

ex.

1 parent node

1.1 child node

1.2 child node

i have update "1.2 child node" rename to "1.3 child node"

and reload treeview so it will chage...

how set tree node.selected index = 1.3 child node....

View 3 Replies

Data Controls :: Transfer (Pass) Selected (Checked) DataList Items (Rows) From To Another DataList?

May 7, 2015

How To get Datalist Checkbox  Select Item To The Another Datalist  on click CheckBox 

Code Like

<form id="form1" runat="server">
<div>
<h2 style="background-color: #CCC; font-size: 16px; font-family: Arial, Helvetica, sans-serif; font-weight: 400;" class="heading">Brand</h2>
<asp:DataList ID="DataList5" runat="server" Style="font-weight: 700; color: #CC33FF; background-color: #66FFCC;" Height="100px" Width="122px">
<ItemTemplate>

[code]....

View 1 Replies

Forms Data Controls :: Show DataList Item Index When Using SqlDataSource?

Aug 10, 2010

[Code]....

show DataList Item Index when using SqlDataSource?

View 4 Replies

Forms Data Controls :: Page.setfocus(listbox.selecteditem) Is Not Setting The Focus If Index > 820?

Sep 13, 2010

Why I am unable to setfocus to my list box if the index > 820

My list box contains 2000 items and the index is not able to set the focus if the index > 820

View 6 Replies

Forms Data Controls :: Setting Up A DataList Programatically

Feb 11, 2010

Working on a web part that will contain a datalist. How do you set up various properties such as ItemStyle, AlternatingItemStyles, and all the data binding?

I've search for some keywords but could not find anything relevant.

View 7 Replies

Forms Data Controls :: Get Selected Row Index In Grodview ?

Mar 16, 2011

how can i get row index in selected row in asp gridview in RowCommand ?

View 5 Replies

Forms Data Controls :: How To Make Dropdownlist Box To Selected Index To 0

Sep 13, 2010

I have a dropdownlist1 control in footer template, but when i go to edit command for editing an existing row. at that time. the footer dropdownlist box showing exact index which is selected in edit template dropdownlist box.

dropdownlist1 is in footer template and dropdownlist2 is in edit item template.

same datagrtid i am using for adding new rows via footer template and editing existing rows via edititem template.

how to make dropdownlist1 which is in footer template to selectedindex "0", when i go to editcommand. tried using itemdatabound but not working.

View 4 Replies

Forms Data Controls :: How To Get The Selected Row Index In Grid View

Mar 11, 2010

I have a gridview with dynamic buttons for edit and save.Save button is disable by default. In the edit button command argument i bind the id of the record.

now when i click edit button i want my save button to get enable and edit button will disable for that particular row. I dont kow how to get the selected row index through dynamic button.

View 3 Replies

Forms Data Controls :: Change Gridview Selected Index Dynamically

Feb 9, 2010

I have a gridview. .When I add new data to gridview, I want to change gridview selectex index dynamically. I want to set gridview selectedindex the new added data .

View 2 Replies

Forms Data Controls :: Selected Index Of Radiobuttonlist Inside A Repeater?

Dec 6, 2010

im having a quizz (a question and multiple answer related to the question) , i use an asp repeater to display the questionand a nested radiobuttonlist inside the item template for the related answer:

[Code]....

I do bind the the radiobutton on itemDatabound, i need to store the answer selected by the user, for that i used the following method:

[Code]....

but the rptAns referring to the radiobuttonlist (there is only one quiz at a time), the selectedindex always remain at the first index even when the user does change the selected radio button.i have made a check when on item databound to see if the page is a postback before opulating the radiobuttonlist.

View 3 Replies

Forms Data Controls :: Find Index Of Selected Column In Asp Gridview?

Mar 13, 2011

i know how to find the index of selected row in asp gridview , but i need to find the index of selected column in asp gridview ?for ex:i have i gridview contains columns with header ( the header is the primary key i looking for ) , this grid contain linkbutton , i want to get the column header name on click on linkbutton ?

View 5 Replies

Forms Data Controls :: Using The Selected Index Of A Gridview Where The Key Includes UserID?

Jul 17, 2010

I have Gridview1 that brings up the columns Resorts, Seasons, Seasons_ID, Resorts_ID, and User_ID

The three ID's are all foreign keys from related tables, and they are together a combined primary key of the table being accessed (they were defined that way to prevent duplicate entries for any User/Resort/Season combination).

Now the problem: I want to use the selected row from that gridview in the WHERE clause of a SQLDatasource by setting the WHERE clause up like:

WHERE (([Resort_ID] = @Resort_ID) AND ([Season_ID] = @Season_ID) AND ([User_ID] = @User_ID)) , with the parameters each coming from statements like

Gridview1.SelectedValue

When I select a row in the Gridview, I get the following error:

Operand type clash: uniqueidentifier is incompatible with int

I am pretty sure this has to do with the User_ID being in the WHERE clause.

So I have tried something like this to access the selected index:

Gridview1.DataKeys(Gridview1.SelectedIndex).Value

This does not work, as it seems to return only the first key (of three) in the DataKeyNames list.

So the question: How can I use the SelectedIndex of that gridview for such a purpose when the key contains a UserID?

View 8 Replies

Forms Data Controls :: How To Capture A DropDownList Selected Index Change Event

Sep 15, 2010

I have a gridview that receives data based on selection from a primary dropdownlist object. Works.

Within the gridview, there is a dropdownlist whose selected index is based on the query from the primary dropdownlist. Works.

Problem.

How do I force the used to change whatever value that the dropdownlist contains after they make their initial selection from the primary dropdownlist; except the default value of "make a selection".

Gridview, contains a checkbox which drives whether a selected row is inserted into the data base. The databind in done using an ObjectDataSource on the presentation page, not in the code behind.

View 11 Replies

Forms Data Controls :: Gridview Selected Index Changed In Update Panel?

Jun 14, 2010

I have a gridview where I am opening a popup page when user selects a row. If I am not using update panel then Select button is able to open popup page.

If I am adding Update panel, the popup page is unable to open. What could be the cause?

[Code]....

View 2 Replies

Forms Data Controls :: Selected Indexchanged Is Not Setting Labels?

Mar 8, 2010

What is wrong with this? I provided my selected indexchanged and gridview.

[Code]....

View 7 Replies

Forms Data Controls :: Dropdown List In Gridview - Selected Index While Saving The Record

Oct 22, 2010

I am developing page for maintaing employee record using Visual Studio 2008, MS SQL server 2005. I am able to fetch and display all the employee information in gridview, the gridview have the dropdown list to display the employee type [ Part Time, Full Time, Permanent , Contract ], in the item template i am having dropdown list. IN the dropdown list i am displaying this. But While saving the record in gridview the droppdown selected index are changed to 0 of other dropdown list.

the user may be change the dropdown value from permanent to contract, or so. but while click on the save button in gridview, all the previous selection are gone, and always showing the first record of dropdown list. I know this is happening because we are doing dropdown list bind on onRowDataBound.

View 11 Replies

Forms Data Controls :: Selected Index Changed Event Fired On Page PostBack?

Jan 13, 2011

On Button click(postback), my dropdownlist of gridview is getting blank, so i m getting error of "Object Reference...." on the line "ddl.selecteditem.value"Also, dropdownlist's selectedindexchanged event is fired on Button Click(Page Postback), which is making the dropdownlist to go blank. AutoPostBack of dropdownlist is set as False,

View 8 Replies

Forms Data Controls :: Capture The Selected Index Changed Event For A Dropdown List?

Mar 22, 2010

I have a details view control which contains a dropdown list.

I would like to update a row in the DV based on when the selected index change event occurs in another row of the

So far I know that 1) Place code in detailsview1.rowupdating event .

2) Make a row copy, not sure about the syntax here

Dim
aRow As DetailsViewRow =
Me.DetailsView1.Rows(DetailsView1.Rows.Item(?))
3) Find my DDL
Dim aDDL as dropdownlist = CType(aDDL.cells(?).Findcontrol("Dropdownlist3"0, dropdownlist)
If aDLL.selected IndexChanged then
Dim aTextbox as textbox = Ctype(detaislview.cells(?).findcontrol("Textbox6", textbox6)
aTextbox.text = now()

View 9 Replies

Forms Data Controls :: Scrolling To Datalist Selected Row?

Feb 2, 2011

After I changed Datalist1.SelectedIndex (and loading datas)page loads and loses curret scroll position in page.how can I autoscroll (focus) to selected Item of Dataliist after I changed Datalist1.SelectedIndex .so each time datalist Item Selection It goes to top of page.How can I revent this ? or keep position or scroll to selected Datalist item ?

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved