I want to display 4 latest records in every row from each category.
I am getting the results but am stuck at the way I am displaying the data.
HTML on ASPX Page
<div class="row">
<!--Start OF Live Feeds-->
<div class="col-xs-6 col-sm-3 mix livefeeds">
<div class="work-item">
<div class="image-holder">
<a href="images/gallery/1.jpg" id="hrefLiveFeedsOne" runat="server" onserverclick="LiveFeedsOneEvent">
<img src="images/gallery/1.jpg" id="imgLiveFeedsOne" runat="server" />
<h4>
<asp:Label ID="lblLiveFeedsOne" runat="server" Text="Don’t quit your job if you work in"></asp:Label></h4>
</a>
</div>
</div>
</div>
<div class="col-xs-6 col-sm-3 mix livefeeds">
<div class="work-item">
<div class="image-holder">
<a href="images/gallery/1.jpg" id="hrefLiveFeedsTwo" runat="server" onserverclick="LiveFeedsTwoEvent">
<img src="images/gallery/1.jpg" id="imgLiveFeedsTwo" runat="server" />
<h4>
<asp:Label ID="lblLiveFeedsTwo" runat="server" Text="Live Feeds Two: Don’t quit your job if you work in 1 of these 5 industries"></asp:Label></h4>
</a>
</div>
</div>
</div>
<div class="col-xs-6 col-sm-3 mix livefeeds">
<div class="work-item">
<div class="image-holder">
<a href="images/gallery/1.jpg" id="hrefLiveFeedsThree" runat="server" onserverclick="LiveFeedsThreeEvent">
<img src="images/gallery/1.jpg" alt="" id="imgLiveFeedsThree" runat="server" />
<h4>
<asp:Label ID="lblLiveFeedsThree" runat="server" Text="Live Feeds Three: Don’t quit your job if you work in 1 of these 5 industries"></asp:Label></h4>
</a>
</div>
</div>
</div>
<div class="col-xs-6 col-sm-3 mix livefeeds">
<div class="work-item">
<div class="image-holder">
<a href="images/gallery/1.jpg" id="hrefLiveFeedsFour" runat="server" onserverclick="LiveFeedsFourEvent">
<img src="images/gallery/1.jpg" alt="" id="imgLiveFeedsFour" runat="server" />
<h4>
<asp:Label ID="lblLiveFeedsFour" runat="server" Text="Live Feeds Four: Don’t quit your job if you work in 1 of these 5 industries"></asp:Label></h4>
</a>
</div>
</div>
</div>
</div>
Binding data
private void BindData()
{
using (SqlConnection con = new SqlConnection(cn))
{
using (SqlCommand cmd = new SqlCommand("usp_NewsByCategories"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con;
sda.SelectCommand = cmd;
sda.Fill(dt);
ViewState["data"] = dt;
imgLiveFeedsOne.Src = dt.Rows[55]
imgPromotionFour.Src = dt.Rows[4]["ImagePath"].ToString();
hrefPromotionFour.HRef = dt.Rows[4]["Identity"].ToString();
lblPromotionFour.Text = dt.Rows[4]["Headline"].ToString();
imgPromotionFive.Src = dt.Rows[3]["ImagePath"].ToString();
hrefPromotionFive.HRef = dt.Rows[3]["Identity"].ToString();
lblPromotionFive.Text = dt.Rows[3]["Headline"].ToString();
imgPromotionSix.Src = dt.Rows[2]["ImagePath"].ToString();
hrefPromotionSix.HRef = dt.Rows[2]["Identity"].ToString();
lblPromotionSix.Text = dt.Rows[2]["Headline"].ToString();
imgPromotionSeven.Src = dt.Rows[1]["ImagePath"].ToString();
hrefPromotionSeven.HRef = dt.Rows[1]["Identity"].ToString();
lblPromotionSeven.Text = dt.Rows[1]["Headline"].ToString();
imgPromotionEight.Src = dt.Rows[0]["ImagePath"].ToString();
hrefPromotionEight.HRef = dt.Rows[0]["Identity"].ToString();
lblPromotionEight.Text = dt.Rows[0]["Headline"].ToString();
}
}
}
}
Its totally a wrong way to do it as there will be 80 recods on a aspx page
Question is how do I write a code to get the design as per the count of Datatable and in a foreach loop bind it and as per the count create the images,labels dynamically,in MVC its easy
Like
@{
<div class="row">
@foreach (var item in Model)
{
<div class="col-xs-6 col-sm-3 mix livefeeds">
<div class="work-item">
<div class="image-holder">
<a href="images/gallery/1.jpg" id="hrefLiveFeedsFive">
<img src="@item.imageID" alt=""/>
<h4>
<span>@Html.Raw(@item.Title)</span>
</a>
</div>
</div>
</div>
}
</div>
}
How do i write the same thing on ASPX Design View like we do it on a MVC Razor. Note : As the server doesn't supports MVC am doing it in Webform.