how to use edit radlistview contain combobox - asp.net

I have problem with edit of radlistview.
in edit radlistview contain combobox.
How to I set value for combobox and update value of edit radlistview to database.
I have code asp.net:
<telerik:RadListView ID="RadListView2" runat="server" Width="100%" DataSourceID="SqlDataSource2" AllowPaging="True" PageSize="5" DataKeyNames="bc_truongcap">
<LayoutTemplate>
<div class="RadListView RadListView_Default">
<table style="width: 100%;">
<thead>
<tr class="rlvHeader">
<td>Chỉnh sửa
</td>
<td>Trường</td>
<td>Khối ngành</td>
</tr>
</thead>
<tfoot>
<tr>
<td>
<telerik:RadDataPager ID="RadDataPager1" runat="server" PageSize="3">
<Fields>
<telerik:RadDataPagerButtonField FieldType="Numeric" />
</Fields>
</telerik:RadDataPager>
</td>
</tr>
</tfoot>
<tbody>
<tr id="itemPlaceholder" runat="server">
</tr>
</tbody>
</table>
</div>
</LayoutTemplate>
<ItemTemplate>
<tr class="rlvI">
<td>
<asp:LinkButton ID="LinkButton1" CommandName="Edit" runat="server">Đổi</asp:LinkButton></td>
<td><%#Eval("bc_truongcap") %></td>
<td><%#Eval("bc_loaibang") %></td>
</tr>
</ItemTemplate>
<EditItemTemplate>
<tr class="rlvIEdit">
<td>
<fieldset>
Thay đổi Bằng
<table>
<tr>
<td>Trường cấp</td>
<td><%#Eval("bc_truongcap") %></td>
</tr>
<tr>
<td>Loại bằng</td>
<td>
<telerik:RadComboBox ID="bangcap" Text='<%#Bind("bc_truongcap")%>' runat="server" Skin="Office2007">
<Items>
<telerik:RadComboBoxItem runat="server" Text="Phổ thông" Value="Phổ thông" Selected='<%#Eval("bc_truongcap") =="Phổ thông" ? true :false %>' />
<telerik:RadComboBoxItem runat="server" Text="Trung cấp" Value="Trung cấp" Selected='<%#Eval("bc_truongcap") =="Trung cấp" ? true :false %>' />
<telerik:RadComboBoxItem runat="server" Text="Cao đẳng" Value="Cao đẳng" />
<telerik:RadComboBoxItem runat="server" Text="Đại học" Value="Đại học" />
<telerik:RadComboBoxItem runat="server" Text="Thạc sĩ" Value="Thạc sĩ" />
<telerik:RadComboBoxItem runat="server" Text="Khác" Value="Khác" />
</Items>
</telerik:RadComboBox>
<%--<asp:TextBox ID="TextBox2" runat="server" Text='<%#Bind("bc_loaibang") %>'>
</asp:TextBox>--%></td>
</tr>
<tr>
<td>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="update">Cập nhập</asp:LinkButton></td>
<td>
<asp:LinkButton ID="LinkButton3" runat="server" CommandName="cancel">Thoát</asp:LinkButton></td>
</tr>
</table>
</fieldset>
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<div class="RadListView RadListView_Default">
<div class="rlvEmpty">
Chưa có cập nhập băng cấp.
</div>
</div>
</EmptyDataTemplate>
</telerik:RadListView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:InterFindWorkConnectionString %>"
SelectCommand="SELECT id_nganh, bc_truongcap, bc_loaibang FROM BangCap WHERE (id_gmailntv = #id_gmailntv) AND (bc_status = 0)" UpdateCommand="Update Bangcap set bc_truongcap=#bc_truongcap , bc_loaibang = #bc_loaibang where bc_truongcap=#bc_truongcap ">
<SelectParameters>
<asp:SessionParameter Name="id_gmailntv" SessionField="user" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="bc_truongcap" />
<asp:Parameter Name="bc_loaibang" />
</UpdateParameters>
</asp:SqlDataSource>
how to update to database with value of selected combobox?

Check the Two-Way DataBinding in ListView thread in the Telerik KB.

Related

Delete\Update\Insert item in ListView

I have a ListView which has many templates (InsertItemTemplate, AlternatingItemTemplate, EditItemTemplate, EmptyDataTemplate, ItemTemplate, LayoutTemplate, SelectedItemTemplate)
I have this datasource:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:CouncilsConnectionString %>"
SelectCommand="SELECT [EmpID], [EmpName], [UserName], [password], [Email], [Mobile] FROM [Emp] WHERE ([FlageDel] = #FlageDel)"
DeleteCommand="DELETE FROM Emp WHERE (EmpId = #did)"
InsertCommand="INSERT INTO Emp(EmpName, UserName, password, Email, Mobile) VALUES (#inm, #ius, #ips, #iem, #imob)"
UpdateCommand="UPDATE Emp SET EmpName = #ename, UserName = #nm, password = #ps, Email = #em, Mobile = #mob WHERE (EmpId = #eid)">
<DeleteParameters>
<asp:Parameter Name="did" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="inm" />
<asp:Parameter Name="ius" />
<asp:Parameter Name="ips" />
<asp:Parameter Name="iem" />
<asp:Parameter Name="imob" />
</InsertParameters>
<SelectParameters>
<asp:Parameter DefaultValue="0" Name="FlageDel" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="ename" />
<asp:Parameter Name="nm" />
<asp:Parameter Name="ps" />
<asp:Parameter Name="em" />
<asp:Parameter Name="mob" />
<asp:Parameter Name="eid" />
</UpdateParameters>
</asp:SqlDataSource>
And in the ItemTemplate I have
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Update" />
</td>
I want to know how can I associate the delete button with the data source command so that it deletes the item when the button is clicked. The same thing for update\insert operations.
Here is the entire ListView Code
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" InsertItemPosition="LastItem">
<AlternatingItemTemplate>
<tr style="background-color: #FFFFFF;color: #000000;">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" CommandArgument="#did" Text="حذف" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="تعديل" />
</td>
<td>
<asp:Label ID="EmpNameLabel" runat="server" Text='<%# Eval("EmpName") %>' />
</td>
<td>
<asp:Label ID="UserNameLabel" runat="server" Text='<%# Eval("UserName") %>' />
</td>
<td>
<asp:Label ID="passwordLabel" runat="server" Text='<%# Eval("password") %>' />
</td>
<td>
<asp:Label ID="EmailLabel" runat="server" Text='<%# Eval("Email") %>' />
</td>
<td>
<asp:Label ID="MobileLabel" runat="server" Text='<%# Eval("Mobile") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<EditItemTemplate>
<tr style="background-color: #999999;">
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" CommandArgument="#eid" Text="حفظ" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="إلغاء" />
</td>
<td>
<asp:TextBox ID="EmpNameTextBox" runat="server" Text='<%# Bind("EmpName") %>' />
</td>
<td>
<asp:TextBox ID="UserNameTextBox" runat="server" Text='<%# Bind("UserName") %>' />
</td>
<td>
<asp:TextBox ID="passwordTextBox" runat="server" Text='<%# Bind("password") %>' />
</td>
<td>
<asp:TextBox ID="EmailTextBox" runat="server" Text='<%# Bind("Email") %>' />
</td>
<td>
<asp:TextBox ID="MobileTextBox" runat="server" Text='<%# Bind("Mobile") %>' />
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<table runat="server" style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;">
<tr>
<td>ليس هناك أي بيانات حاليا.</td>
</tr>
</table>
</EmptyDataTemplate>
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="إضافة" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="مسح" />
</td>
<td>
<asp:TextBox ID="EmpNameTextBox" runat="server" Text='<%# Bind("EmpName") %>' />
</td>
<td>
<asp:TextBox ID="UserNameTextBox" runat="server" Text='<%# Bind("UserName") %>' />
</td>
<td>
<asp:TextBox ID="passwordTextBox" runat="server" Text='<%# Bind("password") %>' />
</td>
<td>
<asp:TextBox ID="EmailTextBox" runat="server" Text='<%# Bind("Email") %>' />
</td>
<td>
<asp:TextBox ID="MobileTextBox" runat="server" Text='<%# Bind("Mobile") %>' />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr style="background-color: #EEE;color: black;">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="حذف" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="تعديل" />
</td>
<td>
<asp:Label ID="EmpNameLabel" runat="server" Text='<%# Eval("EmpName") %>' />
</td>
<td>
<asp:Label ID="UserNameLabel" runat="server" Text='<%# Eval("UserName") %>' />
</td>
<td>
<asp:Label ID="passwordLabel" runat="server" Text='<%# Eval("password") %>' />
</td>
<td>
<asp:Label ID="EmailLabel" runat="server" Text='<%# Eval("Email") %>' />
</td>
<td>
<asp:Label ID="MobileLabel" runat="server" Text='<%# Eval("Mobile") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server" style="direction: rtl; width: 100%">
<tr runat="server">
<td runat="server">
<table id="itemPlaceholderContainer" runat="server" border="1" style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif; text-align: center; vertical-align: middle">
<tr runat="server" style="background-color: #5D7B9D;color: #FFF;">
<th runat="server" style="text-align: center"></th>
<th runat="server" style="text-align: center">الاسم</th>
<th runat="server" style="text-align: center">اسم المستخدم</th>
<th runat="server" style="text-align: center">كلمة المرور</th>
<th runat="server" style="text-align: center">الايميل</th>
<th runat="server" style="text-align: center">الجوال</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="text-align: center;background-color: #5D7B9D;font-family: Verdana, Arial, Helvetica, sans-serif;color: #FFFFFF">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr style="background-color: #E2DED6;font-weight: bold;color: #333333;">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="حذف" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="تعديل" />
</td>
<td>
<asp:Label ID="EmpNameLabel" runat="server" Text='<%# Eval("EmpName") %>' />
</td>
<td>
<asp:Label ID="UserNameLabel" runat="server" Text='<%# Eval("UserName") %>' />
</td>
<td>
<asp:Label ID="passwordLabel" runat="server" Text='<%# Eval("password") %>' />
</td>
<td>
<asp:Label ID="EmailLabel" runat="server" Text='<%# Eval("Email") %>' />
</td>
<td>
<asp:Label ID="MobileLabel" runat="server" Text='<%# Eval("Mobile") %>' />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
Sorry for the delay, but is the delete button not working? generally when you use the templates, it automatically sets it all up so when you click the delete button it runs the deletecommand. However, the Parameters you currently have
<InsertParameters>
<asp:Parameter Name="inm" />
<asp:Parameter Name="ius" />
<asp:Parameter Name="ips" />
<asp:Parameter Name="iem" />
<asp:Parameter Name="imob" />
</InsertParameters>
Don't seem to be really doing any thing, you need to add what they should be expecting. IE string, char, int... something along those lines.
The other part, is the command argument that you have added to your buttons. I don't think you need that.
Sorry if this is super late and you already figured it out.

ASP.NET Model Binding, ListView & CheckBox.Checked

I am using ASP.NET 4.5 Model Binding to present items in a ListView control with editing.
<asp:ListView ID="Results" runat="server" SelectMethod="SelectClientStatus" DataKeyNames="ID" ItemPlaceholderID="itemPlaceHolder" ItemType="ClientStatus" OnItemCommand="Results_ItemCommand" InsertItemPosition="LastItem" UpdateMethod="UpdateClientStatus" InsertMethod="InsertClientStatus">
<LayoutTemplate>
<table>
<tr>
<th runat="server">
<asp:LinkButton ID="SortByDescription" runat="server" ClientIDMode="Static" CommandName="Sort" CommandArgument="Description" Text="Description" />
</th>
<th>Active</th>
<th></th>
</tr>
<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
</table>
<agp:PagerControl runat="server" ID="PagerControl" />
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<%#: Item.Description%>
</td>
<td>
<%#: Item.IsClientActive %>
</td>
<td>
<asp:LinkButton ID="Edit" runat="server" ClientIDMode="Static" CommandName="Edit" CommandArgument="<%#: Item.ID %>" Text="Edit" />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
When I add my EditItemTemplate, I have a Checkbox and I am trying to bind the Checked property to the model...
<EditItemTemplate>
<tr>
<td>
<asp:TextBox ID="Description" runat="server" Text="<%#: BindItem.Description%>" />
</td>
<td>
<asp:CheckBox ID="IsActive" runat="server" Checked="<%#: BindItem.IsClientActive %>" />
</td>
<td>
<asp:LinkButton ID="Update" runat="server" ClientIDMode="Static"
CommandName="Update" CommandArgument="<%#: Item.ID %>"
Text="Update" />
<asp:LinkButton ID="Cancel" runat="server" ClientIDMode="Static"
CommandName="Cancel" CommandArgument="<%#: Item.ID %>"
Text="Cancel" />
</td>
</tr>
</EditItemTemplate>
This is where the problem starts, running the page now shows a message of "CS0030: Cannot convert type 'string' to 'bool'", prompting with the line...
<td>
<asp:CheckBox ID="IsActive" runat="server" Checked="<%#: BindItem.IsClientActive %>" />
</td>
What have I missed? How do I bind the value of IsClientActive to the Checked property of the Checkbox control? It is worth noting that, within the model, the IsClientActive property is defined as a Boolean and not nullable.
My bad; Checked="<%#: BindItem.IsClientActive %>" should have been Checked="<%# BindItem.IsClientActive %>" (note the omission of the colon (:))

Ajax control Toolkit Hover Menu with GridView

Hi there I am trying to achieve the same functionality of the Example Hover menu over at http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/HoverMenu/HoverMenu.aspx
However when my gridview display's and I mouse over the menu comes up but only for the entire gridview not each row like in the example ?. currently the menu buttons do nothing.
<asp:UpdatePanel ID="up1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataSourceID="BookingsSQL"
ShowHeader="False" Width="100%" BackColor="Azure" GridLines="None" >
<Columns>
<asp:BoundField DataField="programme_name" HeaderText="programme_name"
SortExpression="programme_name" />
<asp:BoundField DataField="Start" HeaderText="Start" SortExpression="Start" />
<asp:BoundField DataField="Finish" HeaderText="Finish"
SortExpression="Finish" />
<asp:BoundField DataField="Source" HeaderText="Source"
SortExpression="Source" />
<asp:BoundField DataField="Destination" HeaderText="Destination"
SortExpression="Destination" />
<asp:BoundField DataField="Comment" HeaderText="Comment"
SortExpression="Comment" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="BookingsSQL" runat="server"
ConnectionString="<%$ ConnectionStrings:BookingsConnectionString %>"
SelectCommand="SELECT [programme name] AS programme_name, [Start], [Finish], [Source], [Destination], [Comment] FROM [Bookings]">
</asp:SqlDataSource>
<asp:HoverMenuExtender ID="HoverMenuExtender1" runat="server"
TargetControlID="GridView1"
PopupControlID="PopupMenu"
HoverCssClass="popupHover"
PopupPosition="Left"
OffsetX="0"
OffsetY="0"
PopDelay="50">
</asp:HoverMenuExtender>
<asp:Panel CssClass="popupMenu" ID="PopupMenu" runat="server">
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Edit" Text="Edit" />
<br />
<asp:LinkButton ID="LinkButton2" runat="server"
CommandName="Delete" Text="Delete" />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
Tried a few different ways using jquery hover but this would be the best solution.
Any help please . Thanks.
There is solution.
It's not so tricky to implement a HoverExtender for each row since this showed in sample toolkit sample, as to provide columns headers with sorting.
Draw attention that there is surrogate primary key added to Bookings table for allowing editing all fields values. Also there is used jQuery datepicker plugin for editing Start and Finish fields values. You may use DatePickerExtender from the AjaxControlToolkit instead, but in that case those extenders as well as the HoverExtenders must be added for each row in grid separately.
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="BookingsSQL"
ShowHeader="False" Width="100%" BackColor="Azure" GridLines="None" DataKeyNames="ID">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table runat="server" visible="<%# Container.DataItemIndex == 0 %>">
<tr>
<th width="20%">
<asp:LinkButton runat="server" CommandName="Sort" CommandArgument="programme_name">
Programme Name
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton runat="server" CommandName="Sort" CommandArgument="Start">
Start
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton runat="server" CommandName="Sort" CommandArgument="Finish">
Finish
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton runat="server" CommandName="Sort" CommandArgument="Source">
Source
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton runat="server" CommandName="Sort" CommandArgument="Destination">
Destination
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton runat="server" CommandName="Sort" CommandArgument="Comment">
Comment
</asp:LinkButton>
</th>
</tr>
</table>
<asp:Panel runat="server" ID="ItemContainer">
<table width="100%">
<tr>
<td width="20%">
<%# Eval("programme_name") %>
</td>
<td width="20%">
<%# Eval("Start", "{0:dd/MM/yyyy}") %>
</td>
<td width="20%">
<%# Eval("Finish", "{0:dd/MM/yyyy}") %>
</td>
<td width="20%">
<%# Eval("Source") %>
</td>
<td width="20%">
<%# Eval("Destination") %>
</td>
<td width="20%">
<%# Eval("Comment") %>
</td>
</tr>
</table>
</asp:Panel>
<asp:Panel CssClass="popupMenu" ID="PopupMenu" runat="server">
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Edit" Text="Edit" />
<br />
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="Delete" Text="Delete" />
</asp:Panel>
<ajaxToolkit:HoverMenuExtender runat="server" TargetControlID="ItemContainer" PopupControlID="popupMenu"
HoverCssClass="popupHover" PopupPosition="Left" OffsetX="0" OffsetY="0" PopDelay="50">
</ajaxToolkit:HoverMenuExtender>
</ItemTemplate>
<EditItemTemplate>
<table id="Table1" runat="server" visible="<%# Container.DataItemIndex == 0 %>">
<tr>
<th width="20%">
<asp:LinkButton runat="server" CommandName="Sort" CommandArgument="programme_name">
Programme Name
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton runat="server" CommandName="Sort" CommandArgument="Start">
Start
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton runat="server" CommandName="Sort" CommandArgument="Finish">
Finish
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton runat="server" CommandName="Sort" CommandArgument="Source">
Source
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton runat="server" CommandName="Sort" CommandArgument="Destination">
Destination
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton runat="server" CommandName="Sort" CommandArgument="Comment">
Comment
</asp:LinkButton>
</th>
</tr>
</table>
<asp:Panel runat="server" ID="ItemContainer">
<asp:HiddenField runat="server" ID="IdHiddenField" Value='<%# Bind("ID") %>' />
<table width="100%">
<tr>
<td width="20%">
<asp:TextBox ID="TextBox0" runat="server" Text='<%# Bind("programme_name") %>' />
</td>
<td width="20%">
<asp:TextBox ID="TextBox2" CssClass="datePicker" runat="server" Text='<%# Bind("Start", "{0:dd/MM/yyyy}") %>' />
</td>
<td width="20%">
<asp:TextBox ID="TextBox3" CssClass="datePicker" runat="server" Text='<%# Bind("Finish", "{0:dd/MM/yyyy}") %>' />
</td>
<td width="20%">
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Source") %>' />
</td>
<td width="20%">
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("Destination") %>' />
</td>
<td width="20%">
<asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("Comment") %>' />
</td>
</tr>
</table>
</asp:Panel>
<asp:Panel CssClass="popupMenu" ID="PopupMenu" runat="server">
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Update" CausesValidation="true"
Text="Update" />
<br />
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="Cancel" CausesValidation="false"
Text="Cancel" />
</asp:Panel>
<ajaxToolkit:HoverMenuExtender runat="server" TargetControlID="ItemContainer" PopupControlID="popupMenu"
HoverCssClass="popupHover" PopupPosition="Left" OffsetX="0" OffsetY="0" PopDelay="50">
</ajaxToolkit:HoverMenuExtender>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="BookingsSQL" runat="server" ConnectionString="<%$ ConnectionStrings:BookingsConnectionString %>"
OldValuesParameterFormatString="original_{0}" ConflictDetection="OverwriteChanges"
SelectCommand="SELECT [ID], [programme name] AS programme_name, [Start], [Finish], [Source], [Destination], [Comment] FROM [Bookings]"
DeleteCommand="DELETE FROM [Bookings] WHERE [programme name] = #ID" InsertCommand="INSERT INTO [Bookings] ([programme name], [Start], [Finish], [Source], [Destination], [Comment]) VALUES (#programme_name, #Start, #Finish, #Source, #Destination, #Comment)"
UpdateCommand="UPDATE [Bookings] SET [programme name] = #programme_name, [Start] = #Start, [Finish] = #Finish, [Source] = #Source, [Destination] = #Destination, [Comment] = #Comment WHERE [ID] = #ID">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="programme_name" Type="String" />
<asp:Parameter Name="Start" Type="DateTime" />
<asp:Parameter Name="Finish" Type="DateTime" />
<asp:Parameter Name="Source" Type="String" />
<asp:Parameter Name="Destination" Type="String" />
<asp:Parameter Name="Comment" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="ID" Type="Int32" />
<asp:Parameter Name="Start" Type="DateTime" />
<asp:Parameter Name="Finish" Type="DateTime" />
<asp:Parameter Name="Source" Type="String" />
<asp:Parameter Name="Destination" Type="String" />
<asp:Parameter Name="Comment" Type="String" />
<asp:Parameter Name="programme_name" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
Thanks for such a great help... its working for me i have used SqlDataSource instead of using objectDataSource...
here is my running code that is working great for me....
<asp:UpdatePanel ID="up1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
ShowHeader="False" Width="100%" BackColor="Azure" GridLines="None" DataKeyNames="PageAddID">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table id="Table1" runat="server" visible="<%# Container.DataItemIndex == 0 %>">
<tr>
<th width="20%">
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Sort" CommandArgument="PageName">
Page Name
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="Sort" CommandArgument="PageTitle">
PageTitle
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton ID="LinkButton3" runat="server" CommandName="Sort" CommandArgument="Metakeyword">
Metakeyword
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton ID="LinkButton4" runat="server" CommandName="Sort" CommandArgument="Description">
Description
</asp:LinkButton>
</th>
</tr>
</table>
<asp:Panel runat="server" ID="ItemContainer">
<table width="100%">
<tr>
<td width="20%">
<%# Eval("PageName") %>
</td>
<td width="20%">
<%# Eval("PageTitle") %>
</td>
<td width="20%">
<%# Eval("Metakeyword") %>
</td>
<td width="20%">
<%# Eval("Description") %>
</td>
</tr>
</table>
</asp:Panel>
<asp:Panel CssClass="popupMenu" ID="PopupMenu" runat="server">
<asp:LinkButton ID="LinkButton5" runat="server" CommandName="Edit" Text="Edit" />
<br />
<asp:LinkButton ID="LinkButton6" runat="server" CommandName="Delete" Text="Delete" />
</asp:Panel>
<ajaxToolkit:HoverMenuExtender ID="HoverMenuExtender1" runat="server" TargetControlID="ItemContainer" PopupControlID="popupMenu"
HoverCssClass="popupHover" PopupPosition="Left" OffsetX="0" OffsetY="0" PopDelay="10">
</ajaxToolkit:HoverMenuExtender>
</ItemTemplate>
<EditItemTemplate>
<table id="Table1" runat="server" visible="<%# Container.DataItemIndex == 0 %>">
<tr>
<th width="20%">
<asp:LinkButton ID="LinkButton7" runat="server" CommandName="Sort" CommandArgument="PageName">
Page Name
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton ID="LinkButton8" runat="server" CommandName="Sort" CommandArgument="PageTitle">
PageTitle
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton ID="LinkButton9" runat="server" CommandName="Sort" CommandArgument="Metakeyword">
Metakeyword
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton ID="LinkButton10" runat="server" CommandName="Sort" CommandArgument="Description">
Description
</asp:LinkButton>
</th>
</tr>
</table>
<asp:Panel runat="server" ID="ItemContainer">
<asp:HiddenField runat="server" ID="IdHiddenField" Value='<%# Bind("PageAddID") %>' />
<table width="100%">
<tr>
<td width="20%">
<asp:TextBox ID="TextBox0" runat="server" Text='<%# Bind("PageName") %>' />
</td>
<td width="20%">
<asp:TextBox ID="TextBox2" CssClass="datePicker" runat="server" Text='<%# Bind("PageTitle") %>' />
</td>
<td width="20%">
<asp:TextBox ID="TextBox3" CssClass="datePicker" runat="server" Text='<%# Bind("Metakeyword") %>' />
</td>
<td width="20%">
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Description") %>' />
</td>
</tr>
</table>
</asp:Panel>
<asp:Panel CssClass="popupMenu" ID="PopupMenu" runat="server">
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Update" CausesValidation="true"
Text="Update" />
<br />
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="Cancel" CausesValidation="false"
Text="Cancel" />
</asp:Panel>
<ajaxToolkit:HoverMenuExtender ID="HoverMenuExtender2" runat="server" TargetControlID="ItemContainer" PopupControlID="popupMenu"
HoverCssClass="popupHover" PopupPosition="Left" OffsetX="0" OffsetY="0" PopDelay="10">
</ajaxToolkit:HoverMenuExtender>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
"
OldValuesParameterFormatString="original_{0}" ConflictDetection="OverwriteChanges"
SelectCommand="SELECT * FROM [AddPages]"
DeleteCommand="DELETE FROM [AddPages] WHERE [PageAddId] = #PageAddID"
UpdateCommand="UPDATE [AddPages] SET [PageName] = #PageName, [PageTitle] = #PageTitle, [Metakeyword] = #Metakeyword, [Description] = #Description WHERE [PageAddID] = #PageAddID">
<DeleteParameters>
<asp:Parameter Name="PageAddID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="PageName" Type="string" />
<asp:Parameter Name="PageTitle" Type="string" />
<asp:Parameter Name="Metakeyword" Type="string" />
<asp:Parameter Name="Description" Type="string" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="PageAddID" Type="Int32" />
<asp:Parameter Name="PageName" Type="string" />
<asp:Parameter Name="PageTitle" Type="string" />
<asp:Parameter Name="Metakeyword" Type="string" />
<asp:Parameter Name="Description" Type="string" />
</UpdateParameters>
</ContentTemplate>
</asp:UpdatePanel>

asp.net listview and findcontrol

I have listview and i need to bind the dropdown list in the list view to ListItemCollection which will be built using a function BindPages().
When I clicked on the AddNew Link I am not able to bind the dropdown.
<asp:ListView DataKeyNames="Menuid" OnItemCommand="lvParentMenus_ItemCommand" OnSorting="lvParentMenus_Sorting"
OnDataBound="lvParentMenus_DataBound" DataSourceID="SqlDataSource1" ID="lvParentMenus"
runat="server">
<LayoutTemplate>
<table border="0" id="listview" width="100%" class="grid" cellpadding="0" cellspacing="0">
<thead>
<tr class="listingheader ">
<td width="10%" style="text-align: center; !important">
<input type="checkbox" name="checkbox" id="headercheck" />
</td>
<td id="thsno" runat="server">
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Sort" CommandArgument="Sno"
Text="Sno" />
</td>
<td id="thmenutext" runat="server">
<asp:LinkButton runat="server" ID="LinkButton2" Text="Menu Text" CommandName="Sort"
CommandArgument="MenuText" />
</td>
<td id="thmenuurl" runat="server">
<asp:LinkButton runat="server" ID="LinkButton3" Text="Menu Url" CommandName="Sort"
CommandArgument="MenuUrl" />
</td>
<td id="thlevel" runat="server">
<asp:LinkButton runat="server" ID="LinkButton4" Text="Level of Display" CommandName="Sort"
CommandArgument="level" />
</td>
<td>
Action
</td>
</tr>
</thead>
<tbody>
<tr runat="server" id="itemPlaceholder">
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="3" align="center">
<asp:Label ID="lblMessage" Text="dfdfdfd" runat="server"></asp:Label>
</td>
<td align="right">
<asp:LinkButton Text="Add New" ID="lnkNew" CommandName="FillDropDown" runat="server"
Font-Bold="true" OnClick="AddNew"></asp:LinkButton>
</td>
</tr>
</tfoot>
</table>
<ItemTemplate>
<tr class='<%# Container.DataItemIndex % 2 == 0 ? "lrow1" : "lrow1 altrow" %>'>
<td class="col1" align="center">
<asp:CheckBox runat="server" ID="chkitem"></asp:CheckBox>
</td>
<td class="lrow1">
<%# Eval("Sno")%>
<asp:HiddenField ID="hdnStoreID" runat="server" Value='<%# Eval("MenuId") %>' />
</td>
<td>
<%# Eval("MenuText")%>
</td>
<td>
<asp:DropDownList ID="ddlPagesList" runat="server" DataSource='<%#BindPages()%>'>
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="ddlLevel" runat="server" DataSource='<%#BindLevel(6)%>' SelectedValue='<%# Eval("level")%>'>
</asp:DropDownList>
</td>
<td nowrap="nowrap">
<asp:LinkButton ID="lnkEdit" runat="server" CommandName="Edit">Edit</asp:LinkButton>
|
<asp:LinkButton ID="lnkdelete" runat="server" CommandName="Delete" OnClientClick="javascript:return confirm('Are you sure to delete the current item');">Delete</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
<InsertItemTemplate>
<tr class="lrow1">
<td class="col1" align="center">
</td>
<td class="lrow1">
</td>
<td class="lrow1">
<asp:TextBox ID="txtMenuText" runat="server" Width="80px" Text='<%# Eval("MenuText")%>'
CssClass="inputbox" ValidationGroup="InsertFields" />
<asp:RequiredFieldValidator ID="reqValidCity" ControlToValidate="txtMenuText" runat="server"
ErrorMessage="City Name is required." Display="Dynamic" ValidationGroup="InsertFields">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regValidCity" runat="server" ErrorMessage="Please Enter Alphabets only."
Display="Dynamic" ValidationGroup="g1" ControlToValidate="txtMenuText" ValidationExpression="^[a-zA-Z0-9\s]{2,1000}"></asp:RegularExpressionValidator>
</td>
<td>
<asp:DropDownList ID="ddlPagesList" runat="server" DataSource='<%#BindPages()%>'>
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="ddlLevel" runat="server" DataSourceID="sdsLevel" DataValueField="level"
DataTextField="level">
</asp:DropDownList>
</td>
<td nowrap="nowrap">
<asp:LinkButton ID="lnkinsert" runat="server" OnClick="lnkinsert_Click" ValidationGroup="InsertFields"> Insert</asp:LinkButton>
</td>
</tr>
</InsertItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="usp_getParentMenus"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="ddlRoles" Name="intRoleid" PropertyName="Text" DefaultValue="1"
ConvertEmptyStringToNull="true" Direction="Input" />
</SelectParameters>
</asp:SqlDataSource>
and here is the method BindPAges()
protected ListItemCollection BindPages()
{
string sDir = Request.PhysicalApplicationPath;
if (FirstCount == 0)
DirSearch(sDir);
return collection;
}
When I tried to find the ddlPageList in the AddNew() method it is throwing error "Object referenc not set "
AddNEw() Method:
` protected void AddNew(object sender, EventArgs e)
{
lvParentMenus.InsertItemPosition = InsertItemPosition.FirstItem;
lvParentMenus.FindControl("lnkNew").Visible = false;
lvParentMenus.EditIndex = -1;
sdsLevel.ConnectionString = DBConnectionString.ConnectionString;
Parameter a = new Parameter("intRoleid", DbType.Int32);
a.DefaultValue = ddlRoles.SelectedValue.ToString();
sdsLevel.SelectParameters.Add(a);
sdsLevel.SelectCommand = "usp_getParentMenus";
DropDownList ddlpages = (DropDownList)lvParentMenus.FindControl("ddlPagesList");
string sDir = Request.PhysicalApplicationPath;
DirSearch(sDir);
ddlpages.DataSource = collection;
ddlpages.DataBind();
}
Need urgently.
Thanks.
Please try
DropDownList ddlpages = (DropDownList)lvParentMenus.Items[0].FindControl("ddlPagesList");
Have you tried to use runat=server property in TABLE in Listview?

ItemUpdating NewValues Missing Parameter

I have a formview with several data items that works perfectly except for a single parameter that will not update with the rest of them. The formview's datasource updateparameter is set to do nothing so that I can handle the update in codebehind. Every item works fine, except for one parameter ("salesprice") that is missing in the OldValues and NewValues argument of the ItemUpdating event of the formview. The data DOES pull in to the textbox as it should, formatted properly and all.
I've attached the html, SQL (for getLoanData()), and the codebehind.
Why would every parameter exist in the New/OldValue arguments except the "salesprice" parameter? I've tried populating the textbox without the formatstring, and it's still missing. Is there something about a money SQL datatype that might cause a problem?
HTML:
<asp:FormView ID="fvLoanDetails" runat="server" DataKeyNames="orderid"
DataSourceID="sqlLoanDetails" Width="100%">
<ItemTemplate>
...
</ItemTemplate>
<EditItemTemplate>
<table class="orderSectionHeader">
<tr>
<td style="padding-left:10px;">
<h2>Loan Details</h2>
</td>
<td style="text-align:right;">
<asp:Button ID="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" />
<asp:Button ID="bvnSave" runat="server" Text="Save" CommandName="Update" />
</td>
</tr>
</table>
<table class="orderSection">
<tr>
<td class="orderHeader" style="vertical-align:top;">
Loan Number
</td>
<td>
<asp:Label ID="lblLoanNumber" CssClass="orderData" runat="server"
Text='<%# Bind("loannumber") %>' />
</td>
</tr>
<tr>
<td class="orderHeader">
Business Channel
</td>
<td>
<asp:DropDownList ID="ddlBusinessChannel" runat="server"
DataSourceID="sqlBusinessChannels" DataTextField="BusinessChannel"
DataValueField="BusinessChannel" SelectedValue='<%# Bind("businesschannel") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="sqlBusinessChannels" runat="server"
ConnectionString="<%$ ConnectionStrings:Jade_4 %>"
SelectCommand="SELECT DISTINCT [BusinessChannel] FROM [Loans] ORDER BY [BusinessChannel]">
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td class="orderHeader">
Loan Type
</td>
<td>
<asp:DropDownList ID="ddlLoanType" runat="server"
DataSourceID="sqlLoanType" DataTextField="LoanType"
DataValueField="LoanType" SelectedValue='<%# Bind("loantype") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="sqlLoanType" runat="server"
ConnectionString="<%$ ConnectionStrings:Jade_4 %>"
SelectCommand="SELECT DISTINCT [LoanType] FROM [Loans] ORDER BY [LoanType]">
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td class="orderHeader">
Purpose
</td>
<td>
<asp:DropDownList ID="ddlPurpose" runat="server"
SelectedValue='<%# Bind("purpose") %>'>
<asp:ListItem Text="Purchase" Value="False" />
<asp:ListItem Text="Refinance" Value="True" />
</asp:DropDownList>
</td>
</tr>
<tr id="trSalesPrice" runat="server">
<td class="orderHeader">
Sales Price
</td>
<td>
<asp:TextBox ID="txtSalesPrice" CssClass="orderData" runat="server" Width="100"
Text='<%# Bind("salesprice", "{0:F2}") %>' />
</td>
</tr>
<tr>
<td class="orderHeader">
Borrower
</td>
<td>
<table cellspacing="0">
<tr style="font-size:8pt;padding-bottom:0px;">
<td>First</td><td>Last</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtBFirst" CssClass="orderData" runat="server" Width="80"
Text='<%# Bind("firstname") %>' />
</td>
<td>
<asp:TextBox ID="txtBLast" CssClass="orderData" runat="server" Width="120"
Text='<%# Bind("lastname") %>' />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="orderHeader">
Borrower Email
</td>
<td>
<asp:TextBox ID="txtEmail" CssClass="orderData" runat="server" Width="200"
Text='<%# Bind("email") %>' />
</td>
</tr>
<tr>
<td class="orderHeader" style="vertical-align:top;">
Mailing Address
</td>
<td>
<table cellspacing="0">
<tr style="font-size:8pt;padding-bottom:0px;">
<td colspan="3">Address</td>
</tr>
<tr>
<td colspan="3">
<asp:TextBox ID="txtAddress" CssClass="orderData" runat="server" Width="200"
Text='<%# Bind("address") %>' />
</td>
</tr>
<tr style="font-size:8pt;padding-bottom:0px;">
<td>City</td><td>State</td><td>Zip</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtCity" CssClass="orderData" runat="server" Width="100"
Text='<%# Bind("city") %>' />
</td>
<td>
<asp:TextBox ID="txtState" CssClass="orderData" runat="server" Width="30"
Text='<%# Bind("state") %>' />
</td>
<td>
<asp:TextBox ID="txtZip" CssClass="orderData" runat="server" Width="50"
Text='<%# Bind("zip") %>' />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="orderHeader">
Borrower Primary
</td>
<td>
<asp:TextBox ID="txtBPhone" CssClass="orderData" runat="server"
Text='<%# Bind("phone1", "{0:(###) ###-####}")%>' />
</td>
</tr>
<tr>
<td class="orderHeader">
Borrower Secondary
</td>
<td>
<asp:TextBox ID="txtBCell" CssClass="orderData" runat="server"
Text='<%# Bind("phone2", "{0:(###) ###-####}")%>' />
</td>
</tr>
</table>
</EditItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="sqlLoanDetails" runat="server"
ConnectionString="<%$ ConnectionStrings:Jade_4 %>"
SelectCommand="select #orderid as orderid, * from dbo.getLoanData(#orderid)"
UpdateCommand="select #orderid">
<SelectParameters>
<asp:ControlParameter ControlID="hdnOrderID" Name="orderid"
PropertyName="Value" DefaultValue="0" />
</SelectParameters>
</asp:SqlDataSource>
VB.NET:
Protected Sub fvLoanDetails_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewUpdateEventArgs) Handles fvLoanDetails.ItemUpdating
Dim o As Order = DAL.GetOrderById(hdnOrderID.Value)
Dim l As Loan = DAL.GetLoanByLoanID(o.LoanID)
Dim b As Contact = DAL.GetContactById(l.BorrowerContactID)
l.BusinessChannel = e.NewValues("businesschannel")
l.LoanType = e.NewValues("loantype")
l.Purpose = e.NewValues("purpose")
l.SalesPrice = e.NewValues("salesprice")
DAL.UpdateLoan(l)
b.FirstName = e.NewValues("firstname")
b.LastName = e.NewValues("lastname")
b.Address = e.NewValues("address")
b.City = e.NewValues("city")
b.State = e.NewValues("state")
b.Zip = e.NewValues("zip")
b.Phone = e.NewValues("phone1")
b.Cell = e.NewValues("phone2")
DAL.UpdateContact(b)
End Sub
SQL:
select
l.loannumber, l.businesschannel, l.loantype, l.purpose, l.salesprice, b.firstname, b.lastname, b.email,
b.address, b.city, b.state, b.zip, b.phone as phone1, b.cell as phone2,
dbo.formataddressweb(b.address, '', b.city, b.state, b.zip) as mailingaddress from loans l
join orders o on o.orderid=#orderid
join contacts b on l.borrowercontactid=b.contactid
where l.loanid=(select loanid from orders where orderid=#orderid)
Have you tried a different format string?
Text='<%# Bind("salesprice", "{0:C}") %>'

Resources