I am trying to display the DoctorId key field in my listview and it's coming out always with blanks.
Here is the .aspx page
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="AppointementDataContext" EnableDelete="True" EnableInsert="True"
EnableUpdate="True" EntityTypeName="" TableName="Appointement"
Where="IsAvailable = True && dateApt >= DateTime.Now && doctorId = Doctor.Id &&
doctorid = 1">
<WhereParameters>
<asp:ControlParameter
Name="doctor_name"
ControlID="DropDownList1"
PropertyName="SelectedValue"
Type="String" />
</WhereParameters>
</asp:LinqDataSource>
<asp:ListView ID="ListView1" runat="server" DataKeyNames="aptId"
DataSourceID="LinqDataSource1" InsertItemPosition="LastItem" >
<AlternatingItemTemplate>
<tr style="">
<td>
<asp:Label ID="lblDoctorId" runat="server" Value='<%# Eval("doctorId") %>' />
</td>
<td>
<asp:Label ID="DoctorNameLabel" runat="server"
Text='<%# Eval("Doctor.Doctor_Name") %>' />
</td>
<td>
<asp:Label ID="dateAptLabel" runat="server"
Text='<%# Eval("dateApt", "{0:dd/MM/yyyy}") %>' />
</td>
<td>
<asp:Label ID="hourAptLabel" runat="server"
Text='<%# Eval("hourApt", #"{0:hh\:mm}") %>' />
</td>
<td>
<asp:CheckBox id="MyCheckBox" runat="server"
value='<%# Eval("aptId") %>'
AutoPostBack="true"
OnCheckedChanged="Check_Clicked" />
</td>
</tr>
</AlternatingItemTemplate>
<ItemTemplate>
<tr style="">
<td>
<asp:Label ID="lblDoctorId" runat="server" Value='<%# Eval("doctorId") %>' />
</td>
<td>
<asp:Label ID="DoctorNameLabel" runat="server"
Text='<%# Eval("Doctor.Doctor_Name") %>' />
</td>
<td>
<asp:Label ID="dateAptLabel" runat="server"
Text='<%# Eval("dateApt", "{0:dd/MM/yyyy}") %>' />
</td>
<td>
<asp:Label ID="hourAptLabel" runat="server"
Text='<%# Eval("hourApt", #"{0:hh\:mm}") %>' />
</td>
<td>
<asp:CheckBox id="MyCheckBox" runat="server"
value='<%# Eval("aptId") %>'
AutoPostBack="true"
OnCheckedChanged="Check_Clicked" />
</td>
</tr>
</ItemTemplatee>
All the fields are coming out with the proper values EXCEPT the doctorID.
Here is my Appointement.designer.cs
public partial class Doctor : INotifyPropertyChanging, INotifyPropertyChanged
{
private static PropertyChangingEventArgs emptyChangingEventArgs = new
PropertyChangingEventArgs(String.Empty);
private int _Id;
private string _Doctor_name;
private EntitySet<Appointement> _Appointement;
public partial class Appointement : INotifyPropertyChanging, INotifyPropertyChanged
{
private static PropertyChangingEventArgs emptyChangingEventArgs = new
PropertyChangingEventArgs(String.Empty);
private int _aptId;
private System.Nullable<int> _clientId;
private int _doctorId;
private System.DateTime _dateApt;
private System.TimeSpan _hourApt;
private System.Nullable<bool> _IsAvailable;
private EntityRef<Doctor> _Doctor;
The doctor Name is coming out so it is somehow connected properly. I don't see why the doctorId or the Doctor.Id is not been displayed on the Listview.
Here is how the Appointement.dbml is define:
Appointement Table (aptId,clientId,doctorId,dateApt,hourApt,IsAvailable)
Doctor Table (Id,doctor_name)
I noticed in the Design mode for the Appointement.aspx my column DoctorId is not showing up with DataBound. any idea on how to have it with DataBound ?
Thanks
somehow I don't know why I deleted the table td definition
<asp:Label ID="lblDoctorId" runat="server" Value='<%# Eval("doctorId") %>' />
and I moved them at the end of the definition and it works !!!
If it can help anyone else in the future...
Related
I recently switched a ComboBox in my repeater to a SuggestComboBox (found: here) because it is a contains search rather than a starts-with search. Previously, I was using NamingContainer of that ComboBox to find nearby elements. My new SuggestComboBox does not have this value but in my research on this problem, it looks like all children of a repeater should have this already?
"the NamingContainer property is available in code to any instance of that class or of a derived class." (found: here)
What am I missing?
Here's my repeater:
<asp:Repeater ID="repHW" runat="server" OnItemCommand="rep_ItemCommand">
<HeaderTemplate>
<table style="width:100%; padding-bottom:10px" id="HWtable">
<tr style="font-weight: bold"><td>Product</td><td>Part Number</td><td>Cost</td><td>Unit Price</td><td>Quantity</td><td>Price</td><td>Delete</td></tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<asp:HiddenField ID="Category" Value="Hardware" runat="server"/>
<td><asp:Label ID="Product" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Product.Name") %>' /></td> <!--TODO: make this clickable to edit -->
<td><asp:Label ID="PartNumber" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Product.PartNumber") %>' /></td>
<td><asp:Label ID="PartCost" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Product.Cost") %>' /></td>
<td><asp:Label ID="UnitPrice" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Product.Price") %>' /></td>
<td><asp:Label ID="Quantity" runat="server" Text='<%# Eval("Quantity") %>' /></td>
<td><asp:Label ID="Price" runat="server" Text='<%# Eval("Total") %>' /></td>
<td><asp:Button class="btn btn-danger" ID="DeleteHardware" runat="server" Text="Delete" CommandName="Delete" CommandArgument='<%# Container.ItemIndex %>'/></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<asp:HiddenField ID="AddCategory" Value="Hardware" runat="server"/>
<td><SuggestComboBox runat="server" ID="AddProduct" AutoCompleteMode="SuggestAppend" AutoPostBack="true" OnSelectedIndexChanged="ProductSelected" OnDataBinding="LoadHardwareProducts"/></td>
<td><asp:TextBox runat="server" ID="AddPartNumber" ClientIDMode="static"/></td>
<td><asp:TextBox runat="server" ID="AddPartCost" ClientIDMode="static"/></td>
<td><asp:TextBox runat="server" ID="AddUnitPrice" ClientIDMode="static"/></td>
<td><asp:TextBox runat="server" ID="AddQuantity" ClientIDMode="static"/></td>
<td><asp:Button class="btn btn-success" ID="AddHardware" runat="server" Text="Add" CommandName="Add" CommandArgument='<%# Container.ItemIndex %>' onClientClick="return EmptyFieldCheck('Hardware');"/></td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
and here's my function I am trying to access the other elements in:
protected void ProductSelected(Object source, EventArgs e)
{
SuggestComboBox temp = (SuggestComboBox)source;
List<Product> results = session.Query<Product>()
.Where(x => x.Name == temp.Text)
.ToList();
if(results.Count > 0)
{
Product p = results[0];
var repParent = temp.NamingContainer; //this broke
TextBox partNum = (TextBox)repParent.FindControl("AddPartNumber");
TextBox partCost = (TextBox)repParent.FindControl("AddPartCost");
TextBox unitPrice = (TextBox)repParent.FindControl("AddUnitPrice");
TextBox quantity = (TextBox)repParent.FindControl("AddQuantity");
partNum.Text = p.PartNumber;
partCost.Text = p.Cost.ToString();
unitPrice.Text = p.Price.ToString();
quantity.Text = p.DefaultQuantity.ToString();
}
}
For some reason, all my ListView functions work, except my delete button. I have debugged, and it points to the right method for deletion, but it's just passing all null values. I have no idea what the issue is, everything else seems to be working just fine. here is my listview code:
<asp:ListView ID="EntReqListView" runat="server" InsertItemPosition="LastItem" DataSourceID="EntranceReqODS" Visible="false">
<AlternatingItemTemplate>
<tr style="">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="ProgramIDLabel" runat="server" Text='<%# Bind("ProgramID") %>' />
</td>
<td>
<asp:Label ID="CourseIDLabel" runat="server" Text='<%# Bind("CourseID") %>' />
</td>
<td>
<asp:Label ID="CourseNameLabel" runat="server" Text='<%# Bind("CourseName") %>' />
</td>
<td>
<asp:Label ID="MarkLabel" runat="server" Text='<%# Bind("Mark") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<EditItemTemplate>
<tr style="">
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
<td>
<asp:Label ID="ProgramIDTextBox" runat="server" Text='<%# Bind("ProgramID") %>' />
</td>
<td>
<asp:Label ID="CourseIDTextBox" runat="server" Text='<%# Bind("CourseID") %>' />
</td>
<td>
<asp:Label ID="CourseNameTextBox" runat="server" Text='<%# Bind("CourseName") %>' />
</td>
<td>
<asp:TextBox ID="MarkTextBox" runat="server" Text='<%# Bind("Mark") %>' />
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<table runat="server" style="">
<tr>
<td>No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert"/>
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
</td>
<td>
<asp:TextBox ID="ProgramIDTextBox" runat="server" value="<%# ProgramID.Text %>" Text='<%# Bind("ProgramID")%>' onkeydown="javascript:return false"/>
</td>
<td>
<asp:Label ID="CourseIDTextBox" runat="server" Text='<%# Bind("CourseID") %>' />
</td>
<td>
<asp:DropDownList ID="EntReqCourses" runat="server"
DataSourceID="CourseListODS"
DataTextField="SubjectName"
DataValueField="CourseID"
SelectedValue='<%# Bind("CourseID") %>' AppendDataBoundItems="True">
<asp:ListItem Text="--Select One--" Value="" />
</asp:DropDownList>
</td>
<td>
<asp:TextBox ID="MarkTextBox" runat="server" Text='<%# Bind("Mark") %>' />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr style="">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="ProgramIDLabel" runat="server" Text='<%# Bind("ProgramID") %>' />
</td>
<td>
<asp:Label ID="CourseIDLabel" runat="server" Text='<%# Bind("CourseID") %>' />
</td>
<td>
<asp:Label ID="CourseNameLabel" runat="server" Text='<%# Bind("CourseName") %>' />
</td>
<td>
<asp:Label ID="MarkLabel" runat="server" Text='<%# Bind("Mark") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="">
<th runat="server"></th>
<th runat="server">ProgramID</th>
<th runat="server">CourseID</th>
<th runat="server">CourseName</th>
<th runat="server">Mark</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="">
<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="">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="ProgramIDLabel" runat="server" Text='<%# Bind("ProgramID") %>' />
</td>
<td>
<asp:Label ID="CourseIDLabel" runat="server" Text='<%# Bind("CourseID") %>' />
</td>
<td>
<asp:Label ID="CourseNameLabel" runat="server" Text='<%# Bind("CourseName") %>' />
</td>
<td>
<asp:Label ID="MarkLabel" runat="server" Text='<%# Bind("Mark") %>' />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
I set up all my CRUD methods through the wizard, here is the delete method it goes to:
[DataObjectMethod(DataObjectMethodType.Delete, false)]
public void EntReq_Delete(EntranceRequirementInfo item)
{
using (Pathway_Model context = new Pathway_Model())
{
EntranceRequirement existing = context.EntranceRequirements.Find(item.CourseID, item.ProgramID);
context.EntranceRequirements.Remove(existing);
context.SaveChanges();
}
}
My ODS:
<asp:ObjectDataSource ID="EntranceReqODS" runat="server" DataObjectTypeName="Pathway_System.Entities.DTOs.EntranceRequirementInfo" DeleteMethod="EntReq_Delete" InsertMethod="EntReq_Add" OldValuesParameterFormatString="original_{0}" SelectMethod="EntReqList_byID" TypeName="Pathway_System.BLL.PathwaysController" UpdateMethod="EntReq_Update">
<SelectParameters>
<asp:ControlParameter ControlID="CertificateList" Name="programID" PropertyName="SelectedValue" Type="Int32" DefaultValue="" />
</SelectParameters>
</asp:ObjectDataSource>
I'm having a ListView in grid format which comprises headers as (NAME,ID,ADDRESS,GENDER,MOBILENO,PHOTO,BLOCK).
The BLOCK column consists a CheckBox in each row.
When the checkbox is checked in the BLOCK column,
that particular row of the checkbox should be changed to ReadOnly,
resulting in change of that particular row's backcolor.
my listview coding in aspx is...
<AlternatingItemTemplate>
<tr class="AITtr">
<td>
<asp:Label ID="NAMELabel" runat="server" Text='<%# Eval("NAME") %>' />
</td>
<td>
<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
</td>
<td>
<asp:Label ID="ADDRESSLabel" runat="server" Text='<%# Eval("ADDRESS") %>' />
</td>
<td>
<asp:Label ID="GENDERLabel" runat="server" Text='<%# Eval("GENDER") %>' />
</td>
<td>
<asp:Label ID="MOBILENOLabel" runat="server" Text='<%# Eval("MOBILENO") %>' />
</td>
<td>
<asp:Image ID="Image1" runat="server" ImageUrl='<%#Eval("PHOTO") %>' Height="30" Width="30" />
</td>
<td>
<asp:CheckBox ID="BLOCKCheckBox" runat="server" Checked="false" Enabled="true" />
</td>
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" BackColor="#577109" ForeColor="Black" BorderStyle="Solid" Font-Names="Copperplate Gothic Light" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" BackColor="#577109" ForeColor="Black" BorderStyle="Solid" Font-Names="Copperplate Gothic Light"/>
</td>
</tr>
</AlternatingItemTemplate>
<EditItemTemplate>
<tr class="EITtr">
<td>
<asp:TextBox ID="NAMETextBox" runat="server" Text='<%# Bind("NAME") %>' />
</td>
<td>
<asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>' />
</td>
<td>
<asp:TextBox ID="ADDRESSTextBox" runat="server" Text='<%# Bind("ADDRESS") %>' />
</td>
<td>
<asp:TextBox ID="GENDERTextBox" runat="server" Text='<%# Bind("GENDER") %>' />
</td>
<td>
<asp:TextBox ID="MOBILENOTextBox" runat="server" Text='<%# Bind("MOBILENO") %>' />
</td>
<td>
<asp:TextBox ID="PHOTOTextBox" runat="server" Text='<%# Bind("PHOTO") %>' />
</td>
<td>
<asp:CheckBox ID="BLOCKCheckBox" runat="server" Checked="false" Enabled="true" />
</td>
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update"
Text="Update" BackColor="#577109" ForeColor="Black" BorderStyle="Solid" Font-Names="Copperplate Gothic Light" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Cancel" BackColor="#577109" ForeColor="Black" BorderStyle="Solid" Font-Names="Copperplate Gothic Light" />
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<table runat="server" class="EDTtable" >
<tr>
<td>
No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<InsertItemTemplate>
<tr>
<td>
<asp:TextBox ID="NAMETextBox" runat="server" Text='<%# Bind("NAME") %>' />
</td>
<td>
</td>
<td>
<asp:TextBox ID="ADDRESSTextBox" runat="server" Text='<%# Bind("ADDRESS") %>' />
</td>
<td>
<asp:TextBox ID="GENDERTextBox" runat="server" Text='<%# Bind("GENDER") %>' />
</td>
<td>
<asp:TextBox ID="MOBILENOTextBox" runat="server" Text='<%# Bind("MOBILENO") %>' />
</td>
<td>
<asp:TextBox ID="PHOTOTextBox" runat="server" Text='<%# Bind("PHOTO") %>' />
</td>
<td>
<asp:CheckBox ID="BLOCKCheckBox" runat="server" Checked="false" Enabled="true" />
</td>
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert"
Text="Insert" BackColor="#577109" ForeColor="Black" BorderStyle="Solid" Font-Names="Copperplate Gothic Light"/>
<asp:Button ID="CancelButton1" runat="server" CommandName="Cancel"
Text="Clear" BackColor="#577109" ForeColor="Black" BorderStyle="Solid" Font-Names="Copperplate Gothic Light" />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr class="ITtr">
<td>
<asp:Label ID="NAMELabel" runat="server" Text='<%# Eval("NAME") %>' />
</td>
<td>
<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
</td>
<td>
<asp:Label ID="ADDRESSLabel" runat="server" Text='<%# Eval("ADDRESS") %>' />
</td>
<td>
<asp:Label ID="GENDERLabel" runat="server" Text='<%# Eval("GENDER") %>' />
</td>
<td>
<asp:Label ID="MOBILENOLabel" runat="server" Text='<%# Eval("MOBILENO") %>' />
</td>
<td>
<asp:Image ID="Image" runat="server" ImageUrl='<%#Eval("PHOTO") %>' Height="30" Width="30" />
</td>
<td>
<asp:CheckBox ID="BLOCKCheckBox" runat="server" Checked="false" Enabled="true" />
</td>
<td>
<asp:Button ID="DeleteButton1" runat="server" CommandName="Delete"
Text="Delete" BackColor="#577109" ForeColor="Black" BorderStyle="Solid" Font-Names="Copperplate Gothic Light" />
<asp:Button ID="EditButton1" runat="server" CommandName="Edit" Text="Edit" BackColor="#577109" ForeColor="Black" BorderStyle="Solid" Font-Names="Copperplate Gothic Light"/>
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table ID="itemPlaceholderContainer" runat="server" border="1" class="LTtable" >
<tr runat="server" Class="LTtr">
<th runat="server">
NAME</th>
<th runat="server">
ID</th>
<th runat="server">
ADDRESS</th>
<th runat="server">
GENDER</th>
<th runat="server">
MOBILENO</th>
<th runat="server">
PHOTO</th>
<th runat="server">
BLOCK</th>
<th id="Th1" runat="server">
</th>
</tr>
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" class="LTtd">
</td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr Class=".SITtr">
<td>
<asp:Label ID="NAMELabel" runat="server" Text='<%# Eval("NAME") %>' />
</td>
<td>
<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
</td>
<td>
<asp:Label ID="ADDRESSLabel" runat="server" Text='<%# Eval("ADDRESS") %>' />
</td>
<td>
<asp:Label ID="GENDERLabel" runat="server" Text='<%# Eval("GENDER") %>' />
</td>
<td>
<asp:Label ID="MOBILENOLabel" runat="server" Text='<%# Eval("MOBILENO") %>' />
</td>
<td>
<asp:Label ID="PHOTOLabel" runat="server" Text='<%# Eval("PHOTO") %>' />
</td>
<td>
<asp:CheckBox ID="BLOCKCheckBox" runat="server" Checked="false" Enabled="true" />
</td>
<td>
<asp:Button ID="DeleteButton2" runat="server" CommandName="Delete"
Text="Delete" BackColor="#577109" ForeColor="Black" BorderStyle="Solid" Font-Names="Copperplate Gothic Light" />
<asp:Button ID="EditButton2" runat="server" CommandName="Edit" Text="Edit" BackColor="#577109" ForeColor="Black" BorderStyle="Solid" Font-Names="Copperplate Gothic Light"/>
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
my aspx.cs coding is....
protected void ListView1_OnItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
CheckBox BLOCKCheckBox = (e.Item.FindControl("BLOCKCheckBox") as CheckBox);
if (BLOCKCheckBox.Checked)
{
}
else
{
}
}
}
Kindly help me.....
Thanks....
add oncheckedChanged for block check box and autopostback=true
aspx.cs
protected void BLOCKCheckBox_CheckedChanged(object sender, EventArgs e)
{
CheckBox checkbox = (CheckBox)sender;
ListViewItem itm = (ListViewItem)checkbox.NamingContainer;
if (lstview1.EditIndex == itm.DisplayIndex)
{
(itm.FindControl("NAMETextBox") as TextBox).ReadOnly = true;
}
}
I am trying to build an admin page in order to let the user create edit update the records of the specific table. "District" table has the following properties: DistrictID, DistrictName, Description, DistrictImage, CityFK. Since CityFK is just numbers which represents CityID of the table "City" and does not mean anything to the user I have used a dropdown menu instead and it displays all city names as "DataTextField" and CityIDs as "DataValueField" from the table "City". But my aim is to insert that "DataValueField" into the District table as CityFK. But whenever I enter a new District record and choose a City from the dropdown and press "Insert" button of the listview, CityFK of that regarding record is "0".
I paste the whole listview but if you look at the dropdownlist at the InsertItemTemplate or EditItemTemplate you will what I mean;
<asp:ListView ID="DistrictList" runat="server" DataKeyNames="DistrictID" InsertItemPosition="LastItem" DataSourceID="DistrictEntityDataSource" >
<AlternatingItemTemplate>
<tr style="background-color:#FFF8DC;">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="DistrictIDLabel" runat="server" Text='<%# Eval("DistrictID") %>' />
</td>
<td>
<asp:Label ID="DistrictNameLabel" runat="server" Text='<%# Eval("DistrictName") %>' />
</td>
<td>
<asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>' />
</td>
<td>
<asp:Image ID="DistrictImageLabel" runat="server" Height="100px" ImageUrl='<%# "~/Handlers/ImageHandler.ashx?ID="+Eval("DistrictID")+"&Entity=District"%>'/>
</td>
<td>
<asp:Label ID="CityFKLabel" runat="server" Text='<%# Eval("CityFK") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<EditItemTemplate>
<tr style="background-color:#008A8C;color: #FFFFFF;">
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
<td>
<asp:Label ID="DistrictIDLabel1" runat="server" Text='<%# Eval("DistrictID") %>' />
</td>
<td>
<asp:TextBox ID="DistrictNameTextBox" runat="server" Text='<%# Bind("DistrictName") %>' />
</td>
<td>
<asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>' />
</td>
<td>
<asp:FileUpload ID="FileUploadDistrict2" runat="server" />
</td>
<td>
<asp:DropDownList ID="CityFKDropDownList" runat="server" AutoPostBack="true" DataSourceID="ddlCityFK_DataSource" ViewStateMode="Enabled"
DataTextField="CityName" DataValueField="CityID"
AppendDataBoundItems="true">
<asp:ListItem Text="-Stadt Wählen-" Value="0" ></asp:ListItem>
</asp:DropDownList>
<asp:EntityDataSource ID="ddlCityFK_DataSource" runat="server"
ConnectionString="name=MedicalEntities" DefaultContainerName="MedicalEntities"
EntitySetName="Cities" >
</asp:EntityDataSource>
</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>No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
</td>
<td>
<asp:TextBox ID="DistrictIDTextBox" runat="server" Text='<%# Bind("DistrictID") %>' />
</td>
<td>
<asp:TextBox ID="DistrictNameTextBox" runat="server" Text='<%# Bind("DistrictName") %>' />
</td>
<td>
<asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>' />
</td>
<td>
<asp:FileUpload ID="FileUploadDistrict" runat="server"/>
</td>
<td>
<asp:DropDownList ID="CityFKDropDownList" runat="server" AutoPostBack="true" DataSourceID="ddlCityFK_DataSource" ViewStateMode="Enabled"
DataTextField="CityName" DataValueField="CityID"
AppendDataBoundItems="true">
<asp:ListItem Text="-Stadt Wählen-" Value="0" ></asp:ListItem>
</asp:DropDownList>
<asp:EntityDataSource ID="ddlCityFK_DataSource" runat="server"
ConnectionString="name=MedicalEntities" DefaultContainerName="MedicalEntities"
EntitySetName="Cities">
</asp:EntityDataSource>
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr style="background-color:#DCDCDC;color: #000000;">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="DistrictIDLabel" runat="server" Text='<%# Eval("DistrictID") %>' />
</td>
<td>
<asp:Label ID="DistrictNameLabel" runat="server" Text='<%# Eval("DistrictName") %>' />
</td>
<td>
<asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>' />
</td>
<td>
<asp:Image ID="DistrictImageLabel" runat="server" Height="100px" ImageUrl='<%# "~/Handlers/ImageHandler.ashx?ID="+Eval("DistrictID")+"&Entity=District"%>'/>
</td>
<td>
<asp:Label ID="CityFKLabel" runat="server" Text='<%# Eval("CityFK") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<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;">
<tr runat="server" style="background-color:#DCDCDC;color: #000000;">
<th runat="server"></th>
<th runat="server">DistrictID</th>
<th runat="server">DistrictName</th>
<th runat="server">Description</th>
<th runat="server">DistrictImage</th>
<th runat="server">CityFK</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="text-align: center;background-color: #CCCCCC;font-family: Verdana, Arial, Helvetica, sans-serif;color: #000000;">
<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:#008A8C;font-weight: bold;color: #FFFFFF;">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="DistrictIDLabel" runat="server" Text='<%# Eval("DistrictID") %>' />
</td>
<td>
<asp:Label ID="DistrictNameLabel" runat="server" Text='<%# Eval("DistrictName") %>' />
</td>
<td>
<asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>' />
</td>
<td>
<asp:Image ID="DistrictImageLabel" runat="server" Height="100px" ImageUrl='<%# "~/Handlers/ImageHandler.ashx?ID="+Eval("DistrictID")+"&Entity=District"%>'/>
</td>
<td>
<asp:Label ID="CityFKLabel" runat="server" Text='<%# Eval("CityFK") %>' />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
<asp:EntityDataSource ID="DistrictEntityDataSource" runat="server" ConnectionString="name=MedicalEntities"
DefaultContainerName="MedicalEntities" EnableDelete="True" EnableFlattening="False" EnableInsert="True"
EnableUpdate="True" EntitySetName="Districts" Include="City" EntityTypeFilter="District">
</asp:EntityDataSource>
So I am trying to bind that dropdownlist values to the CityFK during Insert and Edit operations.
I figured it out. As workaround I added one textbox at the same column with the dropdownlist and set its visible attribute to false;
<asp:TextBox ID="CityFKTextBoxInsert" runat="server" Visible="false" Text='<%# Bind("CityFK") %>' />
In case you also encounter such a problem I add the code-behind and asp side here;
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
</td>
<td>
<asp:TextBox ID="DistrictIDTextBox" runat="server" Text='<%# Bind("DistrictID") %>' />
</td>
<td>
<asp:TextBox ID="DistrictNameTextBox" runat="server" Text='<%# Bind("DistrictName") %>' />
</td>
<td>
<asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>' />
</td>
<td>
<asp:FileUpload ID="FileUploadDistrictInsert" runat="server" />
</td>
<td>
<asp:TextBox ID="CityFKTextBoxInsert" runat="server" Visible="false" Text='<%# Bind("CityFK") %>' />
<asp:DropDownList ID="CityFKDropDownListInsert" runat="server" AutoPostBack="true" DataSourceID="ddlCityFK_DataSource2" ViewStateMode="Enabled"
DataTextField="CityName" DataValueField="CityID" OnSelectedIndexChanged="CityFKDropDownListInsert_SelectedIndexChanged"
AppendDataBoundItems="true">
<asp:ListItem Text="-Stadt Wählen-" Value="0" ></asp:ListItem>
</asp:DropDownList>
<asp:EntityDataSource ID="ddlCityFK_DataSource2" runat="server"
ConnectionString="name=MedicalEntities" DefaultContainerName="MedicalEntities"
EntitySetName="Cities" >
</asp:EntityDataSource>
</td>
</tr>
</InsertItemTemplate>
Then I have added a "OnSelectedIndexChanged" event to the dropdown and assign the selected value to that textbox;
protected void CityFKDropDownListInsert_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList DropdownDistrict = (DropDownList)DistrictList.InsertItem.FindControl("CityFKDropDownListInsert");
TextBox DistrictTextBox = (TextBox)DistrictList.InsertItem.FindControl("CityFKTextBoxInsert");
DistrictTextBox.Text = DropdownDistrict.SelectedValue;
}
If you want to apply that solution also to EditItemTemplate only thing you have to do changing that line;
DropDownList DropdownDistrict = (DropDownList)DistrictList.InsertItem.FindControl("CityFKDropDownListInsert");
to this;
DropDownList DropdownDistrict = (DropDownList)DistrictList.EditItem.FindControl("CityFKDropDownListInsert");
"I have a ListView with items to edit and an insert.
The insert item template has several text boxes however I would like to make one of the textboxes readonly and keep a value in it that will persist after every insert.
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
</td>
<td>
<asp:TextBox ID="tc_dateTextBox" runat="server" Text='<%# Bind("tc_date") %>' />
</td>
<td>
<asp:TextBox ID="tc_costTextBox" runat="server" Text='<%# Bind("tc_cost") %>' />
</td>
<td>
<asp:TextBox ID="tc_typeTextBox" runat="server" Text='<%# Bind("tc_type") %>' />
</td>
<td>
<asp:TextBox ID="tc_commentTextBox" runat="server" Text='<%# Bind("tc_comment") %>' />
</td>
<td> </td>
<td>
<asp:TextBox ID="tc_t_idTextBox" runat="server" Text='<%# Bind("tc_t_id") %>' Width="15" ReadOnly="true" />
</td>
</tr>
</InsertItemTemplate>
tc_t_idTextBox is the one that I made readonly and would like that to be the box that keeps the same value on every insert.
In order to make a TextBox readonly you will need to set the ReadOnly=true
example:
<asp:TextBox ReadOnly="True"...
I finally figured out how to fix my issue.
My work around was to add a hidden field to the page.
<asp:HiddenField ID="h_tc_t_id_holder" Value="0" runat="server" />
in code behind I set the value to the hidden field.
h_tc_t_id_holder.Value = App_id;
In the list view i add
OnPreRender="ListView1_OnPreRender"
And in codebehind
protected void ListView1_OnPreRender(object sender, EventArgs e)
{
ListView1.DataBind();
((TextBox)ListView1.InsertItem.FindControl("tc_t_idTextBox")).Text = h_tc_t_id_holder.Value;
}