I have a drop down list where I am trying to add attributes to it's items. By using watch in VS2015, I can see that the attributes have been added but they are not being rendered on the page.
The DDL is in a gridview edititemtemplate. I have tried adding the attributes here with not luck. I was having trouble accessing the drop down list in the row. I ended up using a rowediting handler. I also thought the row might not be fully in edit mode so I tried making the row go into edit mode programmatically before my operations.
<asp:GridView ID="gvUserDetails" runat="server" DataSourceID="SqlUserDetails" AutoGenerateColumns="False" DataKeyNames="ID,EmpID" >
<Columns>
<asp:TemplateField HeaderText="Emp ID" SortExpression="EmpID">
<EditItemTemplate>
<asp:Label runat="server" Text='<%# Bind("EmpID") %>' ID="LabelEmpIDUpdate"></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label runat="server" Text='<%# Bind("EmpID") %>' ID="LabelEmpID"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Notification Name" SortExpression="NotificationName">
<EditItemTemplate>
<asp:DropDownList ID="ddNotificationNameUpdt" runat="server" SelectedValue='<%# Bind("NotificationName") %>' DataSourceID="SqlNotificationNames" DataTextField="Name" DataValueField="Name"></asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="LabelNotificationName" runat="server" Text='<%# Bind("NotificationName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Filter" SortExpression="Filter">
<EditItemTemplate>
<asp:DropDownList ID="ddNotificationFilterUpdt" runat="server" DataSourceID="SqlNotificationFilters" DataTextField="Filter" DataValueField="Filter" SelectedValue='<%# Bind("Filter") %>'></asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="LabelNotificationFilter" runat="server" Text='<%# Bind("Filter") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Crew Filter" SortExpression="CrewFilter">
<EditItemTemplate>
<asp:DropDownList ID="ddCrewFilterUpdt" runat="server" SelectedValue='<%# Bind("CrewFilter") %>'>
<asp:ListItem>*</asp:ListItem>
<asp:ListItem>A</asp:ListItem>
<asp:ListItem>B</asp:ListItem>
<asp:ListItem>C</asp:ListItem>
<asp:ListItem>D</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="LabelCrewFilter" runat="server" Text='<%# Bind("CrewFilter") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date Begin" SortExpression="DateBgn">
<EditItemTemplate>
<asp:TextBox ID="TextBoxBgnUpdt" runat="server" Text='<%# Bind("DateBgn") %>' autocomplete="off" ></asp:TextBox>
<ajaxToolkit:CalendarExtender runat="server" BehaviorID="TextBoxBgnUpdt_CalendarExtender" TargetControlID="TextBoxBgnUpdt" ID="TextBoxBgnUpdt_CalendarExtender" PopupButtonID="TextBoxBgnUpdt"></ajaxToolkit:CalendarExtender>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="LabelDateBgn" runat="server" Text='<%# Bind("DateBgn") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date End" SortExpression="DateEnd">
<EditItemTemplate>
<asp:TextBox ID="TextBoxEndUpdt" runat="server" Text='<%# Bind("DateEnd") %>' autocomplete="off" ></asp:TextBox>
<ajaxToolkit:CalendarExtender runat="server" BehaviorID="TextBoxEndUpdt_CalendarExtender" TargetControlID="TextBoxEndUpdt" ID="TextBoxEndUpdt_CalendarExtender"></ajaxToolkit:CalendarExtender>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="LabelDateEnd" runat="server" Text='<%# Bind("DateEnd") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:Button ID="ButtonUpdate" runat="server" CommandName="Update" Text="Update" CausesValidation="true"/>
<asp:Button ID="ButtonCancel" runat="server" CommandName="Cancel" Text="Cancel" OnClick="ButtonCancel_Click" />
<asp:Button ID="ButtonClearEndDate" runat="server" Text="Clear End Date" OnClick="ButtonClearEndDate_Click" />
</EditItemTemplate>
<ItemTemplate>
<asp:Button ID="btnEditNotification" runat="server" Text="Edit" CommandName="Edit" CausesValidation="False" OnClick="btnEditNotification_Click"/>
<asp:Button ID="btnDeleteNotification" runat="server" Text="Delete" CommandName="Delete" CausesValidation="False" OnClientClick = " return confirm('Are you sure you want to delete this notification?');"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<AlternatingRowStyle BackColor="LemonChiffon" />
</asp:GridView>
Dim gv As GridView = CType(sender, GridView)
gv.Rows(e.NewEditIndex).RowState = DataControlRowState.Edit
For i As Integer = 0 To gv.Rows.Count - 1
If i <> e.NewEditIndex Then
gridRow = gv.Rows(i)
For Each cell As Control In gridRow.Cells
For Each ctl As Control In cell.Controls
If TypeOf ctl Is DropDownList Then
foundDropList = CType(ctl, DropDownList)
If foundDropList.ID.Equals("ddNotificationNameUpdt") Then
Debug.Print("found the list")
dropListToUse = foundDropList
End If
End If
Next
Next
End If
Next
For Each item As ListItem In dropListToUse.Items
item.Attributes("Title") = NotificationNameTable(item.Text)
Next
I am expecting the user to click on the Edit button of the gridview and then dropdownlist of the row being edited to have new attributes called "Title" for each of the list items. Any help?
I was able to figure it out. If I use the RowDataBound event to catch the GridView Edit button click and make sure that the RowState and DataControlRowState.Edit are both greater then 0, I will have the GridView in the state that I want. I then will be able to find my control using e.Row.FindControl(). Then I just loop through the list items and add the attributes which are rendered correctly on screen.
I have a checkboxlist in a formview itemtemplate. In edit mode I want to select the items that are in a datatable. I cannot find how to do this. I am using VB.NET.
ASP.NET code:
<asp:FormView ID="rdf" runat="server" Width="100%" DataSourceID="sqldatasource1" OnItemCreated="rdf_ModeChanging" rendermode="Lightweight" onrowupdating="updatebutton_click" DataKeyNames="applicationid" >
<ItemTemplate>
<fieldset style="width: 97%">
<div>
<br />
<asp:Label runat="server" ID="FiscalOrgNameLabel2" Text="Fiscal Organization: " Style="font-weight: bold; font-size: 15px;"></asp:Label><asp:Label Text='<%# Eval("FiscalOrgName") %>' runat="server" ID="FiscalOrgNameLabel1" />
</div>
<br />
<asp:panel id="cntyPanel" runat="server" >
<asp:label ID="countyLabel" runat="server" style="font-weight: bold; font-size: 15px; "
text="County(s): (if applicable)">
<asp:DataList ID="dlCounty" runat="server" DataSourceID="sqlCounty" Style="font-weight: normal;" >
<ItemTemplate>
<li>
<%# Eval("county") %>
</li>
</ItemTemplate>
</asp:DataList>
</asp:label>
</asp:panel>
<asp:panel id="IHEPanel" runat="server" >
<asp:label ID="instLabel" runat="server" style="font-weight:bold; font-size: 15px; "
text="Institution(s): (if applicable)">
<asp:datalist ID="dlIHE" runat="server" DataSourceID="sqlIHE" style="font-weight:normal;">
<ItemTemplate>
<li >
<%# Eval("Institute") %>
</li>
</ItemTemplate>
</asp:datalist>
</asp:label>
</asp:panel>
<asp:SqlDataSource ID="sqlCounty" runat="server" ConnectionString='<%$ ConnectionStrings:COSIGrantsDB %>' SelectCommand="SELECT dbo.County.County as county, dbo.Application_County.ApplicationId, dbo.Application_County.CountyId
FROM dbo.County INNER JOIN
dbo.Application_County ON dbo.County.CountyID = dbo.Application_County.CountyId where applicationid=#appid">
<SelectParameters>
<asp:QueryStringParameter QueryStringField="appid" Name="appid"></asp:QueryStringParameter>
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource runat="server" ID="sqlGetBehalf" ConnectionString='<%$ ConnectionStrings:COSIGrantsDB %>' SelectCommand="getBehalf" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:QueryStringParameter QueryStringField="appid" Name="appid" Type="Int32"></asp:QueryStringParameter>
<asp:QueryStringParameter QueryStringField="apptypeid" Name="apptypeid" Type="Int32"></asp:QueryStringParameter>
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource runat="server" ID="sqlIHE" ConnectionString='<%$ ConnectionStrings:COSIGrantsDB %>' selectcommand="SELECT dbo.Application_IHE.ApplicationID, dbo.IHE.Institute
FROM dbo.Application_IHE INNER JOIN
dbo.IHE ON dbo.Application_IHE.IHE = dbo.IHE.iheID where applicationid = #appid" SelectCommandType="text">
<SelectParameters>
<asp:QueryStringParameter QueryStringField="appid" Name="appid" Type="Int32"></asp:QueryStringParameter>
</SelectParameters>
</asp:SqlDataSource>
<div>
<div class="rdfCommandButtons">
<hr class="rdfHr" />
<telerik:RadButton runat="server" ButtonType="SkinnedButton" RenderMode="Lightweight" CommandName="Edit" Text="Edit" ID="EditButton" ToolTip="Edit" CausesValidation="False" />
</div>
</fieldset>
</ItemTemplate>
<EditItemTemplate>
<fieldset style="width: 97%"> <br />
<asp:Label ID="editApptypeId" runat="server" Text='<%# Eval("applicationtype") %>'></asp:Label>
<div style="display:table; width:100%">
<div style="display:table-row;">
<div style="display:table-cell;">
Fiscal Organizaton:
</div>
<div class="cell textcell">
<asp:TextBox ID="fiscalOrg" runat="server" Text='<%# Bind("FiscalOrgName") %>'></asp:TextBox>
</div>
</div>
</div>
<div id="cntyPanel" visible="true" runat="server">
<div runat="server" style="font-weight: bold; font-size: 15px;">
County(s):
<asp:CheckBoxList ID="ckCounty" runat="server" RepeatColumns="8" DataTextField="county" DataValueField="countyid" ></asp:CheckBoxList>
<br />
</div>
<div id="IHEPanel" visible="false" runat="server">
<div runat="server" style="font-weight:bold; font-size: 15px;">
Institution(s):
<asp:datalist ID="dlIHE" runat="server" DataSourceID="sqlIHE" style="font-weight:normal;">
<ItemTemplate>
<li >
<%# Eval("Institute") %>
</li>
</ItemTemplate>
</asp:datalist>
</div>
</div>
<asp:SqlDataSource runat="server" ID="sqlGetBehalf" ConnectionString='<%$ ConnectionStrings:COSIGrantsDB %>' SelectCommand="getBehalf" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:QueryStringParameter QueryStringField="appid" Name="appid" Type="Int32"></asp:QueryStringParameter>
<asp:QueryStringParameter QueryStringField="apptypeid" Name="apptypeid" Type="Int32"></asp:QueryStringParameter>
</SelectParameters>
</asp:SqlDataSource>
</div>
<asp:SqlDataSource runat="server" ID="sqlIHE" ConnectionString='<%$ ConnectionStrings:COSIGrantsDB %>' selectcommand="SELECT dbo.Application_IHE.ApplicationID, dbo.IHE.Institute
FROM dbo.Application_IHE INNER JOIN
dbo.IHE ON dbo.Application_IHE.IHE = dbo.IHE.iheID where applicationid = #appid" SelectCommandType="text">
<SelectParameters>
<asp:QueryStringParameter QueryStringField="appid" Name="appid" Type="Int32"></asp:QueryStringParameter>
</SelectParameters>
</asp:SqlDataSource>
</EditItemTemplate>
<EmptyDataTemplate>
<div>
<div class="rdfEmpty">There are no items to be displayed.</div>
</div>
</EmptyDataTemplate>
</asp:FormView>
VB.NET:
Protected Sub rdf_itemcommand(sender As Object, e As FormViewCommandEventArgs) Handles rdf.ItemCommand
Dim county As CheckBoxList = DirectCast(rdf.FindControl("ckCounty"), CheckBoxList)
conn.Open()
Using cmd As New SqlCommand("select * from application_County where applicationid =" + Request.QueryString("appid"), conn)
Using rdr = cmd.ExecuteReader()
If rdr.HasRows Then
Do While rdr.Read
For Each item As ListItem In county.Items
If item.Value = rdr.GetValue(2) Then
item.Selected = True
End If
Next
Loop
End If
End Using
End Using
End Sub
I get an error on county:
Object reference not set to an instance of an object.
When I debug it, county checkboxlist is empty. Why can't I find the checkboxlist in the edititemtemplate?
Without seeing the code you currently have it is a little difficult to guide you, however if you post the code I would be more than happy to help.
You are going to need a for loop in the code behind the goes through and sets everything to checked.
For each checkBoxItem as listItem in [NameOfCheckBox].Items
checkBoxItem.selected = true
next
When I edit items in a Listview from a Dropdown list and press the standard update button the data is not updating.
This is the structure of my database.
CREATE TABLE [dbo].[Assets]
(
[AssetID] [INT] IDENTITY(20000,1) PRIMARY KEY NOT NULL,
[Asset] NVARCHAR(20) NOT NULL,
[Symbol] NVARCHAR(20) NULL,
[AssetType] NVARCHAR(20) CONSTRAINT chk_asttype CHECK (assettype IN ('Currencies',
'Indices',
'Stocks',
'Commodities')) NOT NULL,CREATE TABLE[dbo].[times]
(
timeid [INT] IDENTITY(20010,1) PRIMARY KEY NOT NULL,
timevalues NVARCHAR (15) DEFAULT '15 Minutes' NOT NULL
)CREATE TABLE [dbo].[results]
(
[resultid] [INT] IDENTITY(20016,1) PRIMARY KEY NOT NULL,
[result] [NVARCHAR](10)CONSTRAINT chk_result CHECK (result IN ('Won',
'Lost',
'Draw',
'Prepare',
'New Signal'))
)CREATE TABLE [dbo].[binarysignals]
(
[signalid] [INT] IDENTITY(30000,1) PRIMARY KEY NOT NULL,
[assetid] [INT]CONSTRAINT fk_binastid FOREIGN KEY REFERENCES assets(assetid) NOT NULL,
[signaldate][DATE] DEFAULT Getdate() NOT NULL,
[direction][VARCHAR](4) CONSTRAINT chk_bindirection CHECK (direction IN ('Call',
'Put')) DEFAULT NULL,
[strikeprice] [SMALLMONEY] DEFAULT NULL,
[expiryprice] [SMALLMONEY] DEFAULT NULL,
[starttime][SMALLDATETIME] DEFAULT NULL,
[expirytime][NVARCHAR](20) DEFAULT NULL,
[resultid] [INT]CONSTRAINT fk_binresid FOREIGN KEY REFERENCES results(resultid) DEFAULT 20016 NOT NULL,
[lastupdatedtime][SMALLDATETIME] DEFAULT Getdate() NOT NULL,
)
And here is my ASP.Net markup code
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<script src="Scripts/jquery-1.9.1.min.js"></script>
$(document).ready(function () {
ShowTime();
});
function ShowTime() {
var dt = new Date();
document.getElementById("lblTime").innerHTML = dt.toLocaleTimeString();
window.setTimeout("ShowTime()", 1000);
}
<div>
<label id="lblTime" style="font-weight: bold"></label>
<br />
<asp:SqlDataSource ID="BO" runat="server" ConnectionString="<%$ ConnectionStrings:Signals2UConnectionString %>"
DeleteCommand="DELETE FROM [BinarySignals] WHERE [SignalID] = #SignalID" InsertCommand="INSERT INTO [BinarySignals] ([AssetID]) VALUES (#AssetID)" SelectCommand="SELECT [SignalID], BinarySignals.AssetID ,[Asset], [SignalDate], [Direction], [StrikePrice], [ExpiryPrice], [StartTime], [ExpiryTime], [Result],Results.ResultID FROM [BinarySignals]
INNER JOIN Assets On BinarySignals.AssetID=Assets.AssetID
INNER JOIN Results On BinarySignals.ResultID=Results.ResultID
ORDER BY BinarySignals.AssetID DESC"
UpdateCommand="UPDATE [BinarySignals] SET [AssetID] = #AssetID, [SignalDate] = #SignalDate, [Direction] = #Direction, [StrikePrice] = #StrikePrice, [ExpiryPrice] = #ExpiryPrice, [StartTime] = #StartTime, [ExpiryTime] = #ExpiryTime, [ResultID] = #ResultID WHERE [SignalID] = #SignalID">
<DeleteParameters>
<asp:Parameter Name="SignalID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="AssetID" Type="Int32" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="AssetID" Type="Int32" />
<asp:Parameter DbType="Date" Name="SignalDate" />
<asp:Parameter Name="Direction" Type="String" />
<asp:Parameter Name="StrikePrice" Type="Decimal" />
<asp:Parameter Name="ExpiryPrice" Type="Decimal" />
<asp:Parameter Name="StartTime" Type="DateTime" />
<asp:Parameter Name="ExpiryTime" Type="String" />
<asp:Parameter Name="ResultID" Type="Int32" />
<asp:Parameter Name="SignalID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="Results" runat="server" ConnectionString="<%$ ConnectionStrings:Signals2UConnectionString %>" SelectCommand="SELECT [Result], [ResultID] FROM [Results]"></asp:SqlDataSource>
<asp:ListView ID="ListView1" runat="server" DataSourceID="BO" GroupItemCount="3" InsertItemPosition="LastItem">
<AlternatingItemTemplate>
<td id="Td1" runat="server" style="">SignalID:
<asp:Label ID="SignalIDLabel" runat="server" Text='<%# Eval("SignalID") %>' />
<br />
Asset:
<asp:Label ID="AssetLabel" runat="server" Text='<%# Eval("Asset") %>' />
<br />
SignalDate:
<asp:Label ID="SignalDateLabel" runat="server" Text='<%# Eval("SignalDate","{0:yyyy-MM-dd}") %>' />
<br />
Direction:
<asp:Label ID="DirectionLabel" runat="server" Text='<%# Eval("Direction") %>' />
<br />
StrikePrice:
<asp:Label ID="StrikePriceLabel" runat="server" Text='<%# Eval("StrikePrice") %>' />
<br />
ExpiryPrice:
<asp:Label ID="ExpiryPriceLabel" runat="server" Text='<%# Eval("ExpiryPrice") %>' />
<br />
StartTime:
<asp:Label ID="StartTimeLabel" runat="server" Text='<%# Eval("StartTime") %>' />
<br />
ExpiryTime:
<asp:Label ID="ExpiryTimeLabel" runat="server" Text='<%# Eval("ExpiryTime") %>' />
<br />
Result:
<asp:Label ID="ResultLabel" runat="server" Text='<%# Eval("Result") %>' />
<br />
ResultID:
<asp:Label ID="ResultIDLabel" runat="server" Text='<%# Eval("ResultID") %>' />
<br />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
<br />
</td>
</AlternatingItemTemplate>
<EditItemTemplate>
<td id="Td2" runat="server" style="">SignalID:
Asset:
<asp:TextBox ID="AssetTextBox" runat="server" ReadOnly="true" Text='<%# Bind("Asset") %>' />
<br />
SignalDate:
<asp:TextBox ID="SignalDateTextBox" runat="server" Text='<%# Bind("SignalDate") %>' />
<br />
Direction:
<asp:TextBox ID="DirectionTextBox" runat="server" Text='<%# Bind("Direction") %>' />
<br />
StrikePrice:
<asp:TextBox ID="StrikePriceTextBox" runat="server" Text='<%# Bind("StrikePrice") %>' />
<br />
ExpiryPrice:
<asp:TextBox ID="ExpiryPriceTextBox" runat="server" Text='<%# Bind("ExpiryPrice") %>' />
<br />
StartTime:
<asp:TextBox ID="StartTimeTextBox" runat="server" Text='<%# Bind("StartTime") %>' />
<br />
ExpiryTime:
<asp:TextBox ID="ExpiryTimeTextBox" runat="server" Text='<%# Bind("ExpiryTime") %>' />
<br />
Result:
<asp:DropDownList ID="DropDownList4" runat="server" DataSourceID="Outcome" DataTextField="Result" DataValueField="ResultID" SelectedValue='<%#Bind("ResultID") %>'></asp:DropDownList>
<br />
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
<br />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
<br />
</td>
</EditItemTemplate>
<EmptyDataTemplate>
<table id="Table1" runat="server" style="">
<tr>
<td>No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<EmptyItemTemplate>
<td id="Td3" runat="server" />
</EmptyItemTemplate>
<GroupTemplate>
<tr id="itemPlaceholderContainer" runat="server">
<td id="itemPlaceholder" runat="server"></td>
</tr>
</GroupTemplate>
<InsertItemTemplate>
<td id="Td4" runat="server" style="">Asset:
<asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="Assets" DataTextField="Asset" DataValueField="AssetID" AutoPostBack="True" SelectedValue='<%# Bind("AssetID") %>'>
</asp:DropDownList>
<br />
SignalDate:
<asp:Label ID="SignalDateLabel" runat="server" Text='<%# Bind("SignalDate") %>' />
<br />
Direction:
<asp:TextBox ID="DirectionTextBox" runat="server" Text='<%# Bind("Direction") %>' />
<br />
StrikePrice:
<asp:TextBox ID="StrikePriceTextBox" runat="server" Text='<%# Bind("StrikePrice") %>' />
<br />
ExpiryPrice:
<asp:TextBox ID="ExpiryPriceTextBox" runat="server" Text='<%# Bind("ExpiryPrice") %>' />
<br />
StartTime:
<asp:TextBox ID="StartTimeTextBox" runat="server" Text='<%# Bind("StartTime") %>' />
<br />
ExpiryTime:
<asp:TextBox ID="ExpiryTimeTextBox" runat="server" Text='<%# Bind("ExpiryTime") %>' />
<br />
Result:
<asp:TextBox ID="ResultTextBox" runat="server" Text='<%# Bind("Result") %>' />
<br />
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<br />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
<br />
</td>
</InsertItemTemplate>
<ItemTemplate>
<td id="Td5" runat="server" style="">SignalID:
<asp:Label ID="SignalIDLabel" runat="server" Text='<%# Eval("SignalID") %>' />
<br />
Asset:
<asp:Label ID="AssetLabel" runat="server" Text='<%# Eval("Asset") %>' />
<br />
SignalDate:
<asp:Label ID="SignalDateLabel" runat="server" Text='<%# Eval("SignalDate","{0:yyyy-MM-dd}") %>' />
<br />
Direction:
<asp:Label ID="DirectionLabel" runat="server" Text='<%# Eval("Direction") %>' />
<br />
StrikePrice:
<asp:Label ID="StrikePriceLabel" runat="server" Text='<%# Eval("StrikePrice") %>' />
<br />
ExpiryPrice:
<asp:Label ID="ExpiryPriceLabel" runat="server" Text='<%# Eval("ExpiryPrice") %>' />
<br />
StartTime:
<asp:Label ID="StartTimeLabel" runat="server" Text='<%# Eval("StartTime") %>' />
<br />
ExpiryTime:
<asp:Label ID="ExpiryTimeLabel" runat="server" Text='<%# Eval("ExpiryTime") %>' />
<br />
Result:
<asp:Label ID="ResultLabel" runat="server" Text='<%# Eval("Result") %>' />
<br />
ResultID:
<asp:Label ID="ResultIDLabel" runat="server" Text='<%#Eval("ResultID") %>' />
<br />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
<br />
</td>
</ItemTemplate>
<LayoutTemplate>
<table id="Table2" runat="server">
<tr id="Tr1" runat="server">
<td id="Td6" runat="server">
<table id="groupPlaceholderContainer" runat="server" border="0" style="">
<tr id="groupPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr id="Tr2" runat="server">
<td id="Td7" runat="server" style=""></td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<td id="Td8" runat="server" style="">SignalID:
<asp:Label ID="SignalIDLabel" runat="server" Text='<%# Eval("SignalID") %>' />
<br />
AssetID:
<asp:Label ID="AssetIDLabel" runat="server" Text='<%# Eval("AssetID") %>' />
<br />
Asset:
<asp:Label ID="AssetLabel" runat="server" Text='<%# Eval("Asset") %>' />
<br />
SignalDate:
<asp:Label ID="SignalDateLabel" runat="server" Text='<%# Eval("SignalDate","{0:yyyy-MM-dd}") %>' />
<br />
Direction:
<asp:Label ID="DirectionLabel" runat="server" Text='<%# Eval("Direction") %>' />
<br />
StrikePrice:
<asp:Label ID="StrikePriceLabel" runat="server" Text='<%# Eval("StrikePrice") %>' />
<br />
ExpiryPrice:
<asp:Label ID="ExpiryPriceLabel" runat="server" Text='<%# Eval("ExpiryPrice") %>' />
<br />
StartTime:
<asp:Label ID="StartTimeLabel" runat="server" Text='<%# Eval("SignalDate") %>' />
<br />
ExpiryTime:
<asp:Label ID="ExpiryTimeLabel" runat="server" Text='<%# Eval("ExpiryTime") %>' />
<br />
Result:
<asp:Label ID="ResultLabel" runat="server" Text='<%# Eval("Result") %>' />
<br />
ResultID:
<asp:Label ID="ResultIDLabel" runat="server" Text='<%# Eval("ResultID") %>' />
<br />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
<br />
</td>
</SelectedItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="Assets" runat="server" ConnectionString="<%$ ConnectionStrings:Signals2UConnectionString %>" SelectCommand="SELECT [AssetID], [Asset], [AssetType], [Symbol] FROM [Assets]"></asp:SqlDataSource>
<asp:SqlDataSource ID="times" runat="server" ConnectionString="<%$ ConnectionStrings:Signals2UConnectionString %>" SelectCommand="SELECT DISTINCT [TimeID], [TimeValues] FROM [Times]"></asp:SqlDataSource>
<asp:SqlDataSource ID="Outcome" runat="server" ConnectionString="<%$ ConnectionStrings:Signals2UConnectionString %>" SelectCommand="SELECT [ResultID], [Result] FROM [Results]"></asp:SqlDataSource>
</div>
I try to update the Results value which is a Foreign key stored in the Binary Signals table coming from the Results table. Result field is used as the display text and the ResultId as the value for the dropdown list
Solved. The below was missing from the EditItemTemplate
<asp:Label ID="SignalIDLabel" runat="server" Text='<%# Bind("SignalID")%>'/>
i have two tables dbo.rank( rankID,rankName) and dbo.tbStaff (Staff ID, RankID, StaffName). And dropdownlist which diplays rankName. But in gridview it is showing rankID. How do I make it show rankName as in dropdownlist. Pls HELP!!!
Here is my dropdownlist code:
<asp:DropDownList ID="DropDownList1" runat="server" Height="29px" style="margin-left: 53px" Width="422px"
DataSourceID="SqlDataSource1" DataTextField="RankName" DataValueField="RankID">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ProjectSPConnectionString %>"
SelectCommand="SELECT [RankID],[RankName] FROM [tbRank] ORDER BY [RankID]"
ProviderName="<%$ ConnectionStrings:ProjectSPConnectionString.ProviderName %>">
</asp:SqlDataSource>
And my gv:
you have to customize your grid try this
<asp:GridView ID="gvStaff" runat="server" AutoGenerateColumns ="false">
<Columns>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:Label Text='<%# Eval("RankID") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label Text='<%# Eval("RankName") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
im making a website and ive never used visual studio 2012 before and having difficulty fixing the errors that are appearing, does anyone know what this error is about?
https://imagizer.imageshack.us/v2/821x409q90/661/407a87.png
<asp:Login runat="server" ViewStateMode="Disabled" RenderOuterTable="false">
<LayoutTemplate>
<p class="validation-summary-errors">
<asp:Literal runat="server" ID="FailureText" />
</p>
<fieldset>
<legend>Log in Form</legend>
<ol>
<li>
<asp:Label runat="server" AssociatedControlID="UserName">Username</asp:Label>
<asp:TextBox runat="server" ID="UserName" Width="266px" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="UserName" CssClass="field-validation-error" ErrorMessage="Please enter your username." />
</li>
<li>
<asp:Label runat="server" AssociatedControlID="Password">Password</asp:Label>
<asp:TextBox runat="server" ID="Password" TextMode="Password" Width="263px" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="Password" CssClass="field-validation-error" ErrorMessage="Please enter your password." />
</li>
<li>
<asp:CheckBox runat="server" ID="RememberMe" />
<asp:Label runat="server" AssociatedControlID="RememberMe" CssClass="checkbox">Remember me?</asp:Label>
</li>
</ol>
<asp:Button runat="server" CommandName="Login" Text="Log in" />
</fieldset>
</LayoutTemplate>
</asp:Login>