C# - Databind A Datalist's Page Index To A Button's Commandname?
May 21, 2010
i got this inside a button inside a datalist
CommandName="<%# Container.ItemIndex %>"
when i click the button, i'm expecting commandname to = 0, then 1, then 2, etc, as the datalist progresses, and i'm using that value in the button click's c#but i'm getting this error, i'm pretty sure i'm using this exact setup on another page and i have no problems, any idea what's going on?Server Error in '/' Application.
Compilation ErrorDescription: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.Compiler Error Message: CS0117: 'System.Web.UI.Control' does not contain a definition for 'ItemIndex'
I have a rather large datalist on which I have implemented an editing capability. When I click on my edit link, everything works as expected except that when I bind my data focus returns to to the top of the screen, so my user will have to scroll all the way back down to the item he wants to edit. Is there a way to keep the page centered on the item in question through the databind?
Is there a way to change the values for these two attributes on the client side and have it reflected on the server side after the postback. I tried it but it does not seem to work. I wanted to have one button on the page that I would delegate submits too, and assign these two arguments on the client side. Seems like not possible. Assuming there is a button named "cmd" in the form
I have a GridView with a couple of buttons (asp:Button) in it (last row). Both of them have a CommandName attribute on them and this is handled server side in a grid_RowCommand event handler. Now, this works fine. However, I need to add client side code (Javascript/jQuery) to disable the two buttons when someone clicks on or the other. This is to prevent the user from double-clicking and creating potential havoc.
The way I have done this is by adding OnClientClick on both buttons which calls a javascript function that uses jQuery to disable the two buttons. This works fine, it's just that the page doesn't post back and so the RowCommand event handler never fires.
am creating a web application in using c# with asp.net.
in that am using login page only as normal aspx page. other pages are using masterpage.
when i click logout button in masterpage. page will redirect to login page. after that if i click browser back button it was moving to previous page. how can i prevent this.
am using this following code in master page aspx page. And My log out button code is below.
Im new in datalist and im trying to programmatically bind my database data to my datalistMy problem is, i only able to show the Property Name and description on the ItemTemplateWhen i click on one item to switch to SelectedItemTemplate, most of the information is nothing In my code behind, i got this
I have a datalist and the following link button within the datalist:
[Code]....
I would like to post to a new page and then capture the value from the link button (commandArgument). It appears from other threads I've seen that you have to rebind the datalist in order for the ItemCommand event to fire...is this true? I'd hate to make another DB call to bind my datalist just to make an event fire.
I have following datalist ,to display employee id, name, email ..... datalist have column with link button text " Get Details" and fontcolor "black" , onmouseover of the particular row i want change the color of linkbutton or the image of linkbutton ..
i have a question about HyperLink or LinkButton in Datalist in asp.net. I have HyperLink or LinkButton in Datalist. How when clicking on a linkbutton, if satisfies a certain condition, it will move to a different page, and would not stay current page.
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?)
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=" + Eval("AttachmentId") %>' 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.
We have a Datalist in which we have some data, with every Item we have a button control, What i want to achieve is that on the button click, the data related to that particluar row of Datalist is fetched whose Button control is clicked. How to accomplish this, The problem is how to attach the button control with values related in that partucular row, Note that I am using ArrayList as the Datasource since I am enabling pading via pageDataSource class...
i'm opening a new window and passing on to it variables in a querystring, the values are loaded into a function that is filling my dataset and then filling my Gridview. after i press the button field in my grid to delete an item, the databind doesn't show the updated grid but remains the same. i've noticed that if i navigate back and refresh i see it correctly. in FF btw no problem.
In the below code, when we define the parameters CommandName="Insert" is it actually the same as executing the method Insert? As I can't find Insert anywhere...
Assuming i have two dropdownlists namely: dropdownlistA and dropdownlistB. at page load, i bind values to dropdownlistA. however, depending on the value selected or displayed in dropdownlistA, i want to bind data to dropdownlistB.
Currently, i can bind data to dropdownlistA alright and i already have the required dataset and datatable bind data to dropdownlist. However, dropdownlistB does not bind at page load since the criteria for filling the dataset to bind dropdownlistB (which is the value of dropdownlistA) is not selected. how can i make this wwork.
I am currently considered if this might work. If i were to call the databind for dropdownlistA in a different declared method besides its binding in page load, and select the value from bind in the declared method, would any value be selected?
For example:
In during page load, i call the a method that returns dataset values which i bind to dropdownlistA(caseIDDropDownList). then i call another method (CreateexhibitDataSet()) which contains the dataset values for binding dropdownlistB(exhibitDropDownList). however, i need to define a criteria in the CreateExhibitDataset() method which i will use to generate the dataset values to bind dropdownlistB. if i were to call for the data bind of dropdownlistA(caseIDDropdownList) again in the CreateExhibitDataset() method and pick the value in the dropdown list, would i get any values?
How can i work around this to bind both dropdownlists on page load?
Fixed browser issues by updating a script reference in a referenced user control to use ResolveUrl. Now browser issues are fixed. Still wondering where to put Databind.
I have a series of link buttons in a repeater that switch pages
<asp:Repeater ID="rptPageLinks" runat="server"><ItemTemplate> <asp:LinkButton ID="lnkNewPage" runat="server" Text='<%# Eval("Page") %>' OnCommand="SomeEventHandler" CommandArgument='<%# Eval("Page") %>' CommandName="Redirect" OnClientClick="return confirm('Do you want to save your chanes before you navigate to a new page?');" /> </ItemTemplate></asp:Repeater>
What I want to be able to do is pass the result from the OnClientClick into the EventHandler, ideally by changing the CommandName (i.e. if they click 'yes' on the confirmation it changes the CommandName to "SaveAndRedirect", if they click 'no' it stays as 'Redirect').
I built a simple user control called noteEditor. I need to set/get the CommandName property when the control is used in a gridview. I seem to be able to set it just fine but when I to get it I get a null.Here is the code for my user control:
[Code]....
Here is how I use the control in a gridview on the host page:
[Code]....
As indicated by the comment, e.CommandName always returns an empty string.