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")%>'/>
Related
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
This is my Radgrid and I am trying to call contact type, projectid and ContactName in the .vb code. Please help me obtain it.
As the entire design is under template I was not sure how we access the RadDropDownList, texboxes and ETC.
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" PageSize="50" Width="99%" OnItemUpdated="RadGrid1_ItemUpdated" OnItemInserted="RadGrid1_ItemInserted" OnItemDeleted="RadGrid1_ItemDeleted"
AutoGenerateColumns="False" AutoGenerateEditColumn="True" AutoGenerateDeleteColumn="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowAutomaticDeletes="True" OnDataBound="RadGrid1_DataBound">
<MasterTableView DataSourceID="SqlDataSource1" CommandItemDisplay="Top" DataKeyNames="ProjectID,ContactType">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" Wrap="true" />
<EditItemStyle HorizontalAlign="Left" />
<Columns>
<telerik:GridBoundColumn DataField="ProjectID" UniqueName="ProjectID" FilterControlAltText="Filter ProjectID column" HeaderText="ProjectID" ReadOnly="True" SortExpression="ProjectID" Display="false">
<ColumnValidationSettings>
<ModelErrorMessage Text=""></ModelErrorMessage>
</ColumnValidationSettings>
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn DataField="ContactType" HeaderText="Contact Type">
<ItemTemplate>
<asp:Label Text='<%# Eval("ContactTypeDesc")%>' runat="server" />
</ItemTemplate>
<InsertItemTemplate>
<telerik:RadDropDownList ID="ddlContactType" runat="server" DropDownWidth="100%" SelectedValue='<%# Bind("ContactType") %>' DataSourceID="SqlDataSource2" DataValueField="ContactTypeID" DataTextField="ContactTypeDesc" />
<br />
<asp:RequiredFieldValidator Display="Dynamic" ErrorMessage="* Required Field" ForeColor="Red" ControlToValidate="ddlContactType" runat="server" />
</InsertItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn DataField="ContactName" HeaderText="Contact Name" SortExpression="ContactName" UniqueName="ContactName" FilterControlAltText="Filter ContactName column">
<ItemTemplate>
<asp:Label Text='<%# Eval("ContactName")%>' runat="server" />
</ItemTemplate>
<EditItemTemplate>
<telerik:RadTextBox ID="txtName" runat="server" Text='<%# Bind("ContactName")%>' MaxLength="100"></telerik:RadTextBox><br />
<asp:RequiredFieldValidator Display="Dynamic" ErrorMessage="* Required Field" ForeColor="Red" ControlToValidate="txtName" runat="server" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn DataField="ContactEmailAddress" HeaderText="Contact Email">
<ItemTemplate>
<asp:Label Text='<%# Eval("ContactEmailAddress")%>' runat="server" />
</ItemTemplate>
<EditItemTemplate>
<telerik:RadTextBox ID="txtEmail" runat="server" Text='<%# Bind("ContactEmailAddress")%>' MaxLength="100"></telerik:RadTextBox><br />
<asp:RegularExpressionValidator ID="emailValidator" runat="server" Display="Dynamic" ForeColor="Red"
ErrorMessage="Please, enter valid e-mail address." ValidationExpression="^[\w\.\-]+#[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*(\.[a-zA-Z]{2,3}){1,2}$"
ControlToValidate="txtEmail">
</asp:RegularExpressionValidator>
<asp:RequiredFieldValidator Display="Dynamic" ErrorMessage="* Required Field" ForeColor="Red" ControlToValidate="txtEmail" runat="server" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn DataField="ContactInternationalNumber" HeaderText="International Code">
<ItemTemplate>
<asp:Label Text='<%# String.Format("+{0}", Eval("ContactInternationalNumber"))%>' runat="server" />
</ItemTemplate>
<EditItemTemplate>
<telerik:RadDropDownList ID="ddlCountryCodes" runat="server" DropDownHeight="150px" DropDownWidth="100%" SelectedValue='<%# Bind("ContactInternationalNumber")%>' DataSourceID="SqlDataSource3" DataValueField="CountryCode" DataTextField="Country" />
<br />
<asp:RequiredFieldValidator Display="Dynamic" ErrorMessage="* Required Field" ForeColor="Red" ControlToValidate="ddlCountryCodes" runat="server" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn DataField="ContactPhoneNumber" HeaderText="Contact Phone">
<ItemTemplate>
<asp:Label Text='<%# Eval("ContactPhoneNumber")%>' runat="server" />
</ItemTemplate>
<EditItemTemplate>
<telerik:RadTextBox ID="txtPhoneNumber" runat="server" MaxLength="100" Text='<%# Bind("ContactPhoneNumber")%>' /><br />
<%--<telerik:RadMaskedTextBox ID="radMskTxtPhoneNumber" runat="server" SelectionOnFocus="SelectAll" PromptChar="_" Mask="(###) ###-####" Text='<%# Bind("ContactPhoneNumber")%>' />--%>
<asp:RequiredFieldValidator Display="Dynamic" ErrorMessage="* Required Field" ForeColor="Red" ControlToValidate="txtPhoneNumber" runat="server" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="CreatedBy" HeaderText="Created By" ReadOnly="true" SortExpression="CreatedBy" UniqueName="CreatedBy" FilterControlAltText="Filter CreatedBy column">
<ColumnValidationSettings>
<ModelErrorMessage Text=""></ModelErrorMessage>
</ColumnValidationSettings>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="CreateDate" HeaderText="Create Date" DataFormatString="{0:MM-dd-yyyy}" ReadOnly="true" SortExpression="CreateDate" UniqueName="CreateDate" FilterControlAltText="Filter CreateDate column" DataType="System.DateTime">
<ColumnValidationSettings>
<ModelErrorMessage Text=""></ModelErrorMessage>
</ColumnValidationSettings>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="LastModifiedBy" HeaderText="Last Modified By" ReadOnly="true" SortExpression="LastModifiedBy" UniqueName="LastModifiedBy" FilterControlAltText="Filter LastModifiedBy column">
<ColumnValidationSettings>
<ModelErrorMessage Text=""></ModelErrorMessage>
</ColumnValidationSettings>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="LastModifiedDate" HeaderText="Last Modified Date" ReadOnly="true" DataFormatString="{0:MM-dd-yyyy}" SortExpression="LastModifiedDate" UniqueName="LastModifiedDate" FilterControlAltText="Filter LastModifiedDate column" DataType="System.DateTime">
<ColumnValidationSettings>
<ModelErrorMessage Text=""></ModelErrorMessage>
</ColumnValidationSettings>
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
Please try with the below code snippet.
Protected Sub RadGrid1_ItemInserted(source As Object, e As GridInsertedEventArgs)
Dim editformItem As GridEditFormInsertItem = DirectCast(e.Item, GridEditFormInsertItem)
Dim txtName As RadTextBox = DirectCast(editformItem.FindControl("txtName"), RadTextBox)
Dim ddlContactType As RadDropDownList = DirectCast(editformItem.FindControl("ddlContactType"), RadDropDownList)
' You can access textbox and dropdownlist here
End Sub
OR
Protected Sub RadGrid1_ItemInserted(source As Object, e As GridInsertedEventArgs)
Dim editformItem As GridEditableItem = DirectCast(e.Item, GridEditableItem)
Dim txtName As RadTextBox = DirectCast(editformItem.FindControl("txtName"), RadTextBox)
Dim ddlContactType As RadDropDownList = DirectCast(editformItem.FindControl("ddlContactType"), RadDropDownList)
' You can access textbox and dropdownlist here
End Sub
Let me know if any concern.
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>
I'm creating a website with two pages using a master page. I want to display all the content of my table in gridview on the second page upon logging in.
I don't know what went wrong and why my gridview on the second page won't display. But if I do it on the first page, it's working fine.
Imports System.Data
Imports System.Xml
Partial Class Default2
Inherits System.Web.UI.Page
Dim conn2 As New OleDb.OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0;Data Source=" & Server.MapPath("~/App_Data/Tony.mdb"))
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session("uname") = "" Then
iduser.Text = "Sorry you are not logged-in to view this page."
ElseIf Session("uname") = "Wrong username and/or password. Please try again." Or Session("uname") = "Successfully signed-up! Go back to the home page to log-in" Then
iduser.Text = Session("uname")
Else
Dim cload As New OleDb.OleDbDataAdapter("select * from sample where username='" & Session("uname") & "'", conn2)
Dim tester As New DataSet
iduser.Text = "Welcome " & Session("uname") & "!"
tester.Clear()
cload.Fill(tester)
Session("valid") = tester.Tables(0).DefaultView.Item(0).Item(9)
If Session("valid") = "y" Then
results.DataSource = tester.Tables(0).DefaultView
results.DataBind()
lfn.Visible = True
lln.Visible = True
lag.Visible = True
End If
End If
End Sub
Next is the aspx only now I have added a work around though I still want a clear explaination why wont the gridview show. As you can see I added a data source to the object as a result I didnt need to code the datasource or to databind anymore. Still, I prefer everything to be hard-coded.
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<p style="height: 39px">
<asp:Label ID="iduser" runat="server"></asp:Label>
<asp:GridView ID="results" runat="server" AutoGenerateColumns="False"
Width="249px" EmptyDataText="No Records" DataSourceID="AccessDataSource1">
<Columns>
<asp:BoundField DataField="fname" HeaderText="fname" SortExpression="fname" />
<asp:BoundField DataField="lname" HeaderText="lname" SortExpression="lname" />
<asp:BoundField DataField="age" HeaderText="age" SortExpression="age" />
<asp:BoundField DataField="gender" HeaderText="gender"
SortExpression="gender" />
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/Tony.mdb"
SelectCommand="SELECT [fname], [lname], [age], [gender] FROM [sample] WHERE ([username] = ?)">
<SelectParameters>
<asp:SessionParameter Name="username" SessionField="uname" Type="String" />
</SelectParameters>
</asp:AccessDataSource>
<asp:Button ID="bsearch" runat="server" Text="Search:" Visible="False" />
<asp:TextBox ID="search" runat="server" Visible="False"></asp:TextBox>
</p>
<br />
<asp:ListBox ID="listsearch" runat="server" Width="216px"></asp:ListBox>
<br /><h2>
<asp:Label ID="Label1" runat="server" Text="Edit Profile Here:" Visible="False"></asp:Label>
</h2>
<p>
<asp:Label ID="lfn" runat="server" Text="First Name: "
Visible="False"></asp:Label>
<asp:TextBox ID="fname" runat="server" Enabled="False" Visible="False"></asp:TextBox>
<asp:Label ID="fn" runat="server" ForeColor="#CC3300"></asp:Label>
</p>
<p>
<asp:Label ID="lln" runat="server" Text="Last Name: "
Visible="False"></asp:Label>
<asp:TextBox ID="lname" runat="server" Enabled="False" Visible="False"></asp:TextBox>
<asp:Label ID="ln" runat="server" ForeColor="#CC3300"></asp:Label>
</p>
<p>
<asp:Label ID="lag" runat="server" Text="Age:" Visible="False"></asp:Label>
<asp:TextBox ID="age" runat="server" Enabled="False" Visible="False"></asp:TextBox>
<asp:Label ID="ag" runat="server" ForeColor="#CC3300"></asp:Label>
</p>
<p>
<asp:Label ID="lgen" runat="server" Text="Gender: " Visible="False"></asp:Label>
<asp:DropDownList ID="gender" runat="server" Enabled="False" Visible="False">
<asp:ListItem>Male</asp:ListItem>
<asp:ListItem>Female</asp:ListItem>
</asp:DropDownList>
</p>
<p>
<asp:Label ID="lem" runat="server" Text="Email:" Visible="False"></asp:Label>
<asp:TextBox ID="email" runat="server" Enabled="False" Visible="False"></asp:TextBox>
<asp:Label ID="em" runat="server" ForeColor="#CC3300"></asp:Label>
</p>
<p>
<asp:Label ID="lun" runat="server" Text="Username:" Visible="False"></asp:Label>
<asp:TextBox ID="username" runat="server" Enabled="False" Visible="False"></asp:TextBox>
<asp:Label ID="un" runat="server" ForeColor="#CC3300"></asp:Label>
</p>
<p>
<asp:Label ID="lpw" runat="server" Text="Password:" Visible="False"></asp:Label>
<asp:TextBox ID="pass" runat="server" TextMode="Password" Enabled="False"
Visible="False"></asp:TextBox>
<asp:Label ID="pw" runat="server" ForeColor="#CC3300"></asp:Label>
</p>
<p>
<asp:Label ID="lpw2" runat="server" Text="Re-type Pass:" Visible="False"></asp:Label>
<asp:TextBox ID="pass2" runat="server" TextMode="Password" Enabled="False"
Visible="False"></asp:TextBox>
<asp:Label ID="pw2" runat="server" ForeColor="#CC3300"></asp:Label>
</p>
<p>
<asp:Label ID="ladm" runat="server" Text="Admin?" Visible="False"></asp:Label>
<asp:DropDownList ID="admin" runat="server" Visible="False">
<asp:ListItem>n</asp:ListItem>
<asp:ListItem>y</asp:ListItem>
</asp:DropDownList>
</p>
<p>
<asp:Button ID="bedit" runat="server" Text="Edit" Visible="False" />
<asp:Button ID="badd" runat="server" Text="Add Record" Visible="False" />
<asp:Button ID="bdelete" runat="server" Text="Delete Record" Visible="False" />
</p>
</asp:Content>
You might have forgot to open the connection? Can you edit this
conn2.Open
Before this line:
Dim cload As New OleDb.OleDbDataAdapter("select * from sample where username='" & Session("uname") & "'", conn2)