I create a radlistview and bind it with objectdatasource and define a linkbutton in radlistview
and linkbutton text bind to multi column in radlistview to display multi line in my radlisview.
Now I want when a user click on linkbutton, one row of radlistview that user clicked on is set to a session so I could use it in other pages.
I define selected items in radlistview itemdatabound event or in radlistview itemcommand event, but these events not fire .please help me.
my code is:
<asp:LinkButton ID="lbl1" runat="server"
OnClick="linqbutton1_Click"
CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>'
Text='<%#" ยป"+"buy"+" "+Eval("MelkType")+" "+Eval("MelkSize")+" meter"+" "+Eval("Melkregion") %>'
style="margin-right:0px;direction:rtl;margin-top:20px; ">
</asp:LinkButton>
<br />
<br />
</ItemTemplate>
</telerik:RadListView>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server"
SelectMethod="RentalApartmentGet" TypeName="mymelkclass">
</asp:ObjectDataSource>
You should just extract the values server side after the selection is made, i think this is demo is close to what you need :
http://demos.telerik.com/aspnet-ajax/listview/examples/selecting/defaultcs.aspx
Related
I have a FormView with View and Edit modes, in an UpdatePanel:
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:FormView runat="Server" DefaultMode="ReadOnly" DataSourceID="_myDataSource" >
<ItemTemplate>
<!-- View controls omitted -->
<asp:Button runat="server" CommandName="Edit" Text="Edit" />
</ItemTemplate>
<EditItemTemplate>
<!-- Edit controls omitted -->
<asp:Button runat="server" CommandName="Update" Text="Save" />
<asp:Button runat="server" CommandName="Cancel" Text="Cancel" CausesValidation="false" />
</EditItemTemplate>
</asp:FormView>
</ContentTemplate>
</asp:UpdatePanel>
<!-- Data source (may attributes omitted) -->
<asp:ObjectDataSource ID="_myDataSource" runat="server" />
The Edit and Update buttons / commands work fine, but the Cancel button does nothing.
Any ideas?
The page may not seems to flicker but on clicking Cancel button 2 events are raised by FormView and post back indeed happens. You may refer MSDN. ( Table under Remarks section)
What a 'Cancel' button does is:
Cancels an edit or insert operation and returns the FormView control to the mode specified by the DefaultMode property. Raises the ModeChanged and ModeChanging events.
So you need to handle events for ModeChanged and ModeChanging as shown below:
<asp:formview id="EmployeeFormView"
datasourceid="EmployeeSource" allowpaging="true" datakeynames="EmployeeID"
onmodechanged="EmployeeFormView_ModeChanged"
onmodechanging="EmployeeFormView_ModeChanging"
runat="server">
So, any code that you want to run after ' cancel' button click should utilize these two events as per the requirements.
I had placed debugger in Page_Load, modeChanging() & modechanged(), all of the three events were fired in sequence on clicking 'Cancel' button.
I have the following button on GridView and I want to display a message box to the user for confirming whether he is sure or not for buying the item.(I'm familiar with OnClientClick= return confirm('xxxxx'); ) but on Grid View it is different I can't use this method though.
<asp:ButtonField CommandName="buynow" ImageUrl="~/images/buy.png" HeaderText="BUY" ButtonType="Image"/>
Use itemtemplate field in column node in gridview markup
eg.
<asp:TemplateField HeaderText="Save">
<ItemTemplate>
<asp:Button ID="btnSave" runat="server" Text="Save" OnClientClick="return confirm('Do you want to save?')" />
</ItemTemplate>
</asp:TemplateField>
I have a page which consists of a form on top to add new records into table1 and below that a GridView which shows records in table1 with the ability to edit.
Now the form above is simply one text box which allows you to enter names into table1, this textbox has a required field validator. The validator causes issues however when the gridview is in edit mode as when the user presses 'update' nothing is saved because the validator is triggers (as there is nothing in the form above)
How can I fix this?
You have to put CausesValidation="False" in GridView
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" CausesValidation="False"/>
You can set the RequiredFieldValidator Control and the Add button have the same ValidationGroup name. Something like this:
<asp:Button ID="btnAdd" runat="server" OnClick="btnAdd_Click" ValidationGroup="addValidation" />
<asp:RequiredFieldValidator ID="nameRequired" ControlToValidate="txtName" runat="server" ValidationGroup="addValidation"></asp:RequiredFieldValidator>
...
<asp:Button ID="btnUpdate" runat="server" OnClick="btnUpdate_Click" />
So that, the Update button won't be impacted.
Use cause validation to false in the gridview button.
<asp:Button ID="Button2" runat="server"
CausesValidation="False"
Text="Cancel - Will Not Validate!" />
Here is an example:
http://www.java2s.com/Code/ASP/Asp-Control/CausesValidationFalse.htm
I have a gridview with a dropdownlist for the products description in the footer template.
There is no way to create a SelectedIndexChanged in the IDE and writing it out manually produces an error? How to create code to handle the Selection change? I need to populate the product ids when the product description is selected.
"EDITED"
I tried using the gridview rowediting event assuming that if a row item was changed (ie, a new selection in the dropdown, it would fire, but it doesn't) It appears a gridview event has to be fired when that dropdown list changes, that's where i need the code to go. Any ides on what event?
Here is what the template field markup is:
<asp:TemplateField HeaderText="description" SortExpression="description">
<FooterTemplate>
<asp:DropDownList ID="ddlProductDesc" runat="server" DataSourceID="edsProductDesc" DataTextField="description"
OnSelectedIndexChanged="ddlProductDesc_SelectedIndexChanged">
</asp:DropDownList>
<%--<asp:TextBox ID="tbInsertdescriptiton" Width="350" runat="server"></asp:TextBox>--%>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblProdDesc" runat="server" Text='<%# Bind("description")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Take a look at this:
http://www.c-sharpcorner.com/blogs/7228/asp-net-gridview-dropdown-with-related-records-in-textbox.aspx
I am using a multi page gridview to display bunch of data. Here is the code of the gridview.
<asp:GridView ID="unverifiedlist" runat="server" AutoGenerateColumns="false" AllowSorting="true" AllowPaging="true" OnRowDataBound="unverifiedlist_RowDataBound" style="font-size:12px" >
<Columns><asp:BoundField HeaderText="Surname" DataField="Surname" ReadOnly="true"/></Columns>
<Columns><asp:BoundField HeaderText="Firstname" DataField="Givenname" ReadOnly="true"/></Columns>
......
<Columns><asp:TemplateField HeaderText="Options" >
<ItemTemplate>
<asp:DropDownList ID="options" runat="server" AutoPostBack="true" OnSelectedIndexChanged="options_SelectedIndexChanged">
<asp:ListItem></asp:ListItem>
<asp:ListItem Value="1">Verified</asp:ListItem>
<asp:ListItem Value="2">Rejected</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Reason">
<ItemTemplate>
<asp:TextBox ID="reason" runat="server" OnTextChanged ="reason_TextChanged"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerSettings Visible="false"/>
</asp:GridView>
<asp:DropDownList ID="PageSelect" AutoPostBack="true" runat="server" OnSelectedIndexChanged="PageSelect_SelectedIndexChanged"></asp:DropDownList>
there is a column called "option" which contains a dropdownlist, and it will postback everytime when the selected index was changed to save the edited row. I am trying to avoid this frequent postback. So i think if I can save the whole page before user turn to the next page.
The problem is the "PageSelect" dropdownlist's postback will trigger the page reload first, then onselectedindexchanged event, at this point, the gridview already turned to the next page. So can anyone give me some advice?
You can set EnableSortingAndPagingCallBacks property of the grid view to true , but that wont work if you are using template fields in your gridview, for maintaining the state of the page, you will have to keep the value of current page in session and on page load you can check the session..
I used the gridview itself's paging navigation control instead of my dropdownlist at last. Then I am able to use the pageindexchanging event to save the current page into a session before it goes to the next page