I am trying to retrieve product information such as name,imagepath etc from database using repeater and display in the dataview using code behind. I could successfully retrieve and display the detail but the alignment of the div is not proper.
aspx code:
<div class="row">
<asp:Repeater ID="Repeater2" runat="server"></asp:Repeater>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<div class="col-sm-4 col-lg-4 col-md-4">
<div class="thumbnail">
<img width="250px" height="300px" src="images/<%#Eval("ImagePath") %>" alt="<%#Eval("ProductName") %>">
<div class="caption">
<h4><%#Eval("ProductName") %></h4>
<h4><%#Eval("UnitPrice")%></h4>
</div>
<div class="clearfix">
</div>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
code behind:
SqlDataAdapter sda = new SqlDataAdapter("SELECT ProductName, UnitPrice, ImagePath FROM Products", con);
DataTable dt = new DataTable();
sda.Fill(dt);
DataView dv = new DataView(dt);
dv.Sort = "ProductName"; // Sort by product name
Repeater1.DataSource = dv;
Repeater1.DataBind();
current output:
screenshot
Expected output:
The fourth image should come below the first image according to bootstrap gridview concept which is not happening in my case and because of which the entire layout changes.
I am a beginner and have just started to learn bootstrap.
There are two ways to resolve this issue:
1) End the row after 3 columns and start 2nd row for next 3 columns.
2) Add equal height for columns. You can use following script and add 'resize-height' class to each column.
function setHeight(column) {
var maxHeight = 0;
//Get all the element with class = col
column = jQuery(column);
column.css('height', 'auto');
//Loop all the column
column.each(function () {
//Store the highest value
if (jQuery(this).height() > maxHeight) {
maxHeight = jQuery(this).height();
}
});
//Set the height
column.height(maxHeight);
}
jQuery(window).on('load resize', function () {
setHeight('.resize-height');
});
Related
I have a database that contains all the lastest news. I want the homepage to only display the latest three news items.
My aspx page is setup as:
<div class="row">
<asp:Repeater ID="rptNewsList" runat="server">
<ItemTemplate>
<div class="col-md-4">
<h2><%# Eval("Title") %>
<small><%# Eval("NewsContent") %></small>
</h2>
</div>
<div class="col-md-4">
<h2><%# Eval("Title") %>
<small><%# Eval("NewsContent") %></small>
</h2>
</div>
<div class="col-md-4">
<h2><%# Eval("Title") %>
<small><%# Eval("NewsContent") %></small>
</h2>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
My aspx.cs page is setup as follows, I am using a repeater and the repeater loads the same news into the three columns
I would like col 1 to have latest news and col 2 to have latest news -1 and col 3 to have latest news -2
protected void Page_Load(object sender, EventArgs e)
{
rptNewsList.DataSource = GetNewsList();
rptNewsList.DataBind();
}
private DataTable GetNewsList()
{
DataTable dataTable = new DataTable();
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString"].ConnectionString);
string query = "SELECT top 1 [Id], [Title], [DatePosted], [NewsContent] FROM [News] ORDER BY [Id] DESC";
connection.Open();
SqlCommand command = new SqlCommand(query, connection);
dataTable.Load(command.ExecuteReader());
connection.Close();
return dataTable;
}
My table is configured as follows:
CREATE TABLE [dbo].[News] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[Title] NVARCHAR (100) NOT NULL,
[DatePosted] DATE NOT NULL,
[NewsContent] NTEXT NOT NULL,
[IsRead] BIT DEFAULT ((0)) NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
I think you may need to change your query to something like this:
SELECT DISTINCT TOP 3 [Id], [Title], [DatePosted], [NewsContent] FROM [News]
ORDER BY [DatePosted] DESC
I am trying to display multiple lines from a database into an aspx page. My aspx page name is news.aspx and my table is called news.
I have configured my aspx with the code to display what I want my page to look like. I have attached an image to show I would like it to look like when the page is loaded. The aspx page uses ItemTemplate & asp:Repeater to display the multiple lines.
My aspx page is configured as follows:
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="col-lg-12">
<div class="form-group alert alert-info">
<asp:label runat="server" ID="lblNewsEdits">Latest Sports & Social News Items</asp:label>
</div>
</div>
</div>
</div>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="col-lg-12">
<p>
Title:
<asp:Literal ID="litTitle" runat="server"></asp:Literal>
(<asp:Literal ID="litDatePosted" runat="server"></asp:Literal>)
</p>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="col-lg-12">
<p>
Title:
<asp:Literal ID="litNewsContent" runat="server"></asp:Literal>
</p>
</div>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
My aspx.cs page is configured to pull the information from the news table, I want three column of data to be display in the aspx page (Title, DatePosted and NewsContent).
For the three lines below, I am getting error: "The name "..." does not exist in the current context.
litTitle.text = reader ["Title"].ToString();
litDatePosted.Text = reader["Date Posted"].ToString();
litNewsContent.Text = reader["News Content"].ToString();
The aspx.cx page is configured as follows:
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString"].ConnectionString);
string getNewsQuery = "SELECT Id, Title, DataPosted, Newsontent FROM News WHERE Id = #id";
//get email based on id
SqlCommand getNewsCommand = new SqlCommand(getNewsQuery, connection);
object id = null;
getNewsCommand.Parameters.AddWithValue("#id", id);
connection.Open();
SqlDataReader reader = getNewsCommand.ExecuteReader();
while (reader.Read())
{
litTitle.txt = reader ["Title"].ToString();
litDatePosted.Text = reader["Date Posted"].ToString();
litNewsContent.Text = reader["News Content"].ToString();
}
reader.Close();
connection.Close();
}
My database table is configured as follows:
CREATE TABLE [dbo].[News] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[Title] NVARCHAR (100) NOT NULL,
[DatePosted] DATE NOT NULL,
[NewsContent] NTEXT NOT NULL,
[IsRead] BIT DEFAULT ((0)) NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)[![enter image description here][1]][1]
);
Any ideas?
Try to format your code like this:
litTitle.txt = reader["Title"].ToString();
litDatePosted.Text = reader["DatePosted"].ToString();
litNewsContent.Text = reader["NewsContent"].ToString();
Also in your sql query you have a typo in the SELECT statement, you typed
'Newsontent' instead of 'NewsContent'
EDIT:
Try using the grid view instead of table. GridView should format it selfe acording to the sorce provided by the SqlDataAdapter
protected void Pageaaa_Load(object sender, EventArgs e)
{
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString"].ConnectionString);
string getNewsQuery = "SELECT Id, Title, DataPosted, Newsontent FROM News WHERE Id = #id";
//get email based on id
SqlCommand getNewsCommand = new SqlCommand(getNewsQuery, connection);
object id = null;
getNewsCommand.Parameters.AddWithValue("#id", id);
connection.Open();
SqlDataReader reader = getNewsCommand.ExecuteReader();
SqlDataAdapter da = new SqlDataAdapter();
DataTable dataTable = new DataTable();
da.Fill(dataTable);
GridView1.DataSource = dataTable;
GridView1.DataBind();
connection.Close();
da.Dispose();
}
I have used the media picker as data type for the type, for which the user is going to choose what image they want as the deal image.
But for some reason i can't get the razor syntax to show the image. If I make an If statement to check if the page contains an image then it won't. I think this is a problem that occurs because i have misunderstood something.
My current razor statement:
<img src="#Umbraco.TypedMedia(Model.Content.GetPropertyValue("deal1image")).Url" />
The above code won't show anything.
Hope any of you can guide me to what i do wrong and evt. stuff I'm missing.
This is how my current home.cshtml looks like:
#inherits Umbraco.Web.Mvc.UmbracoTemplatePage
#{
Layout = "Master.cshtml";
}
<div class="container">
<div class="col-md-4">
<!--Image here-->
<img src="#Umbraco.Media(CurrentPage.deal1image).Url" />
<div class="thumbnail thumbnailcustom thumbnailbg1">
<h3>#Umbraco.Field("dealtitle1")</h3>
<p>#Umbraco.Field("dealdescription1")</p>
</div>
</div>
<div class="col-md-4">
<!--Image here-->
<div class="thumbnail thumbnailcustom thumbnailbg2">
<h3>#Umbraco.Field("dealtitle2")</h3>
<p>#Umbraco.Field("dealdescription2")</p>
</div>
</div>
<div class="col-md-4">
<!--Image here-->
<div class="thumbnail thumbnailcustom thumbnailbg3">
<h3>#Umbraco.Field("dealtitle3")</h3>
<p>#Umbraco.Field("dealdescription3")</p>
</div>
</div>
</div>
You need to use Umbraco.Media to get the media. So like this
<img src="#Umbraco.Media(Model.Content.GetPropertyValue("deal1image").ToString()).Url" />
Or
<img src="#Umbraco.Media(CurrentPage.deal1image).Url" />
An example of using Umbraco.Media:
var myPage = CurrentPage.AncestorsOrSelf().Where("DocumentTypeAlias == #0", "yourPageAlias").First();
Umbraco.Media(myPage.myImage.ToString()).Url
Link on OUR Umbraco offers two solutions:
Typed:
#if (Model.Content.HasValue("caseStudyImages"))
{
var caseStudyImagesList = Model.Content.GetPropertyValue<string>("caseStudyImages").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
var caseStudyImagesCollection = Umbraco.TypedMedia(caseStudyImagesList).Where(x => x != null);
foreach (var caseStudyImage in caseStudyImagesCollection)
{
<img src="#caseStudyImage.Url" style="width:300px;height:300px" />
}
}
Dynamic:
#if (CurrentPage.HasValue("caseStudyImages"))
{
var caseStudyImagesList = CurrentPage.CaseStudyImages.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
var caseStudyImagesCollection = Umbraco.Media(caseStudyImagesList);
foreach (var caseStudyImage in caseStudyImagesCollection)
{
<img src="#caseStudyImage.Url" style="width:300px;height:300px" />
}
}
Also, double check your media picker data type alias. Typos are rather common in this part.
This may be a bit clunky compared to other answers but this is what I currently have.
var imageId = Model.Content.GetPropertyValue<int>("eventPoster"); // gets node id
var evId = evpId.Id; // gets image id
var evMd = Umbraco.Media(evId); // I believe this turns the id into a string
var evUrl = evMd.Url; // gets the url of the string
I can't get category images to display in a NopCommerce theme. This is the code I'm using, on the CategoryTemplate.ProductsInGridOrLines.cshtml page.
#if (Model.PictureModel != null && !String.IsNullOrWhiteSpace(Model.PictureModel.ImageUrl))
{
<div class="category-picture">
<img alt="#Model.PictureModel.AlternateText" src="#Model.PictureModel.ImageUrl" title="#Model.PictureModel.Title" />
</div>
}
I've tried removing the if statement, and it just generates <img>.
as far as i am aware, category images should be accessed like this..
#foreach (var item in Model.SubCategories)
{
count3++;
<div class="sub-category-item col-4 alignCenter">
<h2 class="title">
<a href="#Url.RouteUrl("Category", new { SeName = item.SeName })" title="#item.PictureModel.Title" class="green">
#item.Name</a>
</h2>
<div class="picture">
<a href="#Url.RouteUrl("Category", new { SeName = item.SeName })" title="#item.PictureModel.Title">
<img alt="#item.PictureModel.AlternateText" src="#item.PictureModel.ImageUrl"
title="#item.PictureModel.Title" /></a>
</div>
</div>
if (count3 %3 == 0)
{
#Html.Raw("</div><div class='row'>")
}
}
this is a slightly modified version of the original nopcommerce code in a site i'm currently working on and this code works.
note that images are taken from the item.pictureModel rather than Model.PictureModel.
this is assuming that you have not moved this code into a separate file.
hope this helps
Before using your code you should add the following code to the Category method in the CatalogController:
//prepare category picture model
int picId = category.PictureId;
int picSize = _mediaSettings.CategoryThumbPictureSize;
var categoryPicCacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_PICTURE_MODEL_KEY, model.Id, picSize, true, _workContext.WorkingLanguage.Id, _webHelper.IsCurrentConnectionSecured(), _storeContext.CurrentStore.Id);
model.PictureModel = _cacheManager.Get(categoryPicCacheKey, () =>
{
var pictureModel = new PictureModel()
{
FullSizeImageUrl = _pictureService.GetPictureUrl(picId),
ImageUrl = _pictureService.GetPictureUrl(picId, picSize),
Title = string.Format(_localizationService.GetResource("Media.Category.ImageLinkTitleFormat"), model.Name),
AlternateText = string.Format(_localizationService.GetResource("Media.Category.ImageAlternateTextFormat"), model.Name)
};
return pictureModel;
});`
<form id="Form1" runat="server">
**<input type="text" id="DateInput" />**
<asp:Repeater ID="DataViewer" runat="server">
<ItemTemplate>
<div style='border: 1px; width: 600px; overflow-x: auto; overflow-y: hidden;'>
<div style='float: left;'>
<%# Eval("DriverName") %> </div>
</div>
</ItemTemplate>
</asp:Repeater>
this is my function:
protected void Page_Load(object sender, EventArgs e)
{
OrderDataRepository rep = new OrderDataRepository();
var results = rep.GetAllOrderData().Where(x => x.POD_DATE == ????????????????).
GroupBy(o => o.User).
Select(g =>
new
{
DriverId = g.Key.Id,
DriverName = g.Key.Name,
OrderCount = g.Count(),
OrderCountWhereNameIsNotNull =
g.Count(o => o.RECEIVE_NAME != null)
}).ToList();
DataViewer.DataSource = results;
DataViewer.DataBind();
}
at the moment i get all the results from the table,
i want to add Datepicker for jQuery http://keith-wood.name/datepick.html
<script src="Scripts/jquery.js" type="text/javascript"></script>
when user will pick a day it needs to load all the results for the day that the user picked
please show me how it should be done using jquery with entity framework
You'll need a function in your repository some thing like:
Function SelectOrdersByDate(date as string) as ienumerable(of Order)
Using yourcontext as new context
Dim query = yourcontext.Orders.Where(function(o) o.OrderDate = date).ToList
return query
End Using
End Function
Then call this function via ajax/jquery