asp.net ajax accordion menu categories? - sql

I got 2 sql tables, Categories and Posts. I select top 5 record for each category. But when I use it on accordion menu, it shows category names for each post(repeating).
Here is my code:
<asp:Accordion ID="accMenu" runat="server" DataSourceID="ods_menu" RequireOpenedPane="false">
<HeaderTemplate>
<h3><%# Eval("kategori_adi") %></h3>
</HeaderTemplate>
<ContentTemplate>
<div>
<ul>
<li><asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("post_etiket") %>'>'></asp:HyperLink></li>
</ul>
</div>
</ContentTemplate>
</asp:Accordion>
<asp:ObjectDataSource ID="ods_menu" runat="server" SelectMethod="MenuGetir" TypeName="yonet"></asp:ObjectDataSource>
And my SQL command is like this (I want to select top 5 post for each category):
select top 25 p.post_id,p.post_etiket,k.kategori_id,k.kategori_adi
from post p, kategori k
where k.kategori_id= p.post_kategori_id order by post_date
How can i solve this problem?

Maybe help someone
<HeaderTemplate>
<h3><%# Eval("kategori_adi") %></h3>
</HeaderTemplate>
<ContentTemplate>
<div>
<ul >
<asp:Repeater ID="rp_altmenu" runat="server" DataSourceID="ods_alt_menu">
<ItemTemplate>
<li><asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("post_etiket") %>'></asp:HyperLink></li>
</ItemTemplate>
</asp:Repeater>
</ul>
</div>
</ContentTemplate>
</asp:Accordion>
<asp:ObjectDataSource ID="ods_kategori" runat="server" SelectMethod="KategoriGetir" TypeName="yonet">
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="ods_alt_menu" runat="server" SelectMethod="AltMenuGetir" TypeName="yonet"></asp:ObjectDataSource>
</div>
SQL sp codes of AltMenuGetir
#kategori_id int
AS
select top 5 post_id,post_etiket
from post
where post_kategori_id= #kategori_id
order by post_tarihi
SQL codes of KategoriGetir
select * from kategori
and codebehind:
protected void accMenu_ItemDataBound(object sender, AjaxControlToolkit.AccordionItemEventArgs e)
{
yonet.kategori_idy=Convert.ToInt32(DataBinder.Eval(e.AccordionItem.DataItem, "kategori_id").ToString());
}

Related

Error when building nested ListView with Control Parameter

I cannot figure out why I am getting this error.
Original VB Code:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:db %>" SelectCommand="GetMasterBusinessCategories" SelectCommandType="StoredProcedure">
</asp:SqlDataSource>
<asp:ListView ID="lViewMasterCategories" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<div class="col-md-6">
NAME here
<div class="row">
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:db %>" SelectCommand="GetBusinessSubCategoriesByParentID" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter Name="ParentID" ControlID="lViewMasterCategories" PropertyName="ID"/>
</SelectParameters>
</asp:SqlDataSource>
<asp:ListView ID="lViewSubCategories" runat="server" DataSourceID="SqlDataSource2">
<ItemTemplate>
<div class="col-md-6"></div>
sub-category here
</ItemTemplate>
</asp:ListView>
</div>
</div>
</ItemTemplate>
</asp:ListView>
Stored Procedure(s):
Select ID,CategoryName from BusinessDirectoryCategories with(nolock)
where IsParent = 1 order By CategoryName
and
Select ID,CategoryName from BusinessDirectoryCategories with(nolock)
where ParentID = #ParentID order By CategoryName
(both stored procedures are good and returning correct values)
Error:
enter image description here

Count items in datasource or inside repeater

I found some other questions about this argument but I can't get anything to work.
I have a repeater with datasource, this is my repeater code:
<div class="container dafareoggi" id="divDaFareOggi">
<div runat="server" id="divSegnaposto"></div>
<asp:Repeater runat="server" ID="rptDaFareOggi" DataSourceID="SqlAttivitaDaFareOggi">
<ItemTemplate>
<div id="<%# Eval("id") %>">
<div class="div-titolo" title="<%# Eval("Titolo") %>"><%# Eval("Titolo") %></div>
<div class="div-testo" title="<%# Eval("Note") %>"><%# Eval("Note") %></div>
<div>
<table style="width: 100%;margin-top:0.5em;padding-right:0.2em;">
<tr>
<td style="width: 50%; text-align: left;">
<asp:ImageButton runat="server" ImageUrl="~/images/gabri.png" Width="2.3em" Height="2.3em" ToolTip='<%#Eval("tecnico")%>' Enabled="false" Visible='<%# IIf(Eval("idutente") = 8, True, False) %>'/>
<asp:ImageButton runat="server" ImageUrl="~/images/giuse.png" Width="2.3em" Height="2.3em" ToolTip='<%#Eval("tecnico")%>' Enabled="false" Visible='<%# IIf(Eval("idutente") = 2, True, False) %>'/>
<asp:ImageButton runat="server" ImageUrl="~/images/robi.png" Width="2.3em" Height="2.3em" ToolTip='<%#Eval("tecnico")%>' Enabled="false" Visible='<%# IIf(Eval("idutente") = 5, True, False) %>'/>
</td>
<td style="width: 50%; text-align: right; ">
<asp:LinkButton CommandName="delAttivita" CommandArgument='<%#Eval("ID")%>' runat="server" ID="lnkDelAtt" CausesValidation="False" OnClientClick="return confirm('Sei sicuro di voler eliminare questa attivita?');"><i class="fa fa-trash fa-lg" title="Elimina attività"></i></asp:LinkButton>
<asp:LinkButton CommandName="editAttivita" CommandArgument='<%#Eval("ID")%>' runat="server" ID="lnkEditAtt"><i class="fa fa-pencil-square fa-lg" title="Modifica attività"></i></asp:LinkButton>
</td>
</tr>
</table>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
In the repeater there is a place card div with id divSegnaposto (2nd row) and then a bunch of div may be loaded accordingly to data read from the db.
What I want is that when there are no data to load, so divSegnaposto is the only item, to show it and, vice versa, when there are 1 ore more other divs, to hide it.
I figure that I should count the number of items inside the repeater or rows inside datasouce (I'm using EF), so I tried different approach in repeater_databound_event, but for example repeater.items.count is always 0.
How can I achieve the goal?
I ended up using a linq query that gets the same as the sqldatasource at itembound event and then I check if it's empty or not and show\hide the placecard accordingly. I don't like it too much because makes me mad: I already have all the information I need inside the repeater or the sql data source, so I guess I thought there was an easier, less code-consuming way to do it. But all the answers I found are more complicated than just re-do the query in code behind...

JSSOR with ASP.NET dynamic image

Here is my HTML Code that i am using
<div u="slides">
<div>
<asp:SqlDataSource ID="1" runat="server" ConnectionString="<%$ ConnectionStrings:constr %>" SelectCommand="SELECT Image FROM Gallery"></asp:SqlDataSource>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="1">
<ItemTemplate>
<img u="image" src="<%# "image.ashx?Id="+ Eval("Id") %>" />
</ItemTemplate>
</asp:Repeater>
</div>
The Generic Handler .ashx for the image is THIS
My Issue is that on the Slide, only the last image uploaded come out.
For example, if i uploaded 5 images, only the fifth last uploaded image come up on the slider and it remains static.
I have tested the same generic Handler. it works normal for another slider.
am i missing something.
P.S - the Jssor scripts and css are all in their default values.
nothing was edited.
You placed all images in a single slide.
Please create slide for every image as below.
<div u="slides">
<asp:SqlDataSource ID="1" runat="server" ConnectionString="<%$ ConnectionStrings:constr %>" SelectCommand="SELECT Image FROM Gallery"></asp:SqlDataSource>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="1">
<ItemTemplate>
<div>
<img u="image" src="<%# "image.ashx?Id="+ Eval("Id") %>" />
</div>
</ItemTemplate>
</asp:Repeater>
</asp:SqlDataSource>
</div>

System.MissingMemberException was unhandled by user code

I'm using this code:
Dim VehiclesTable1 = dsVehicleList.Tables(0)
Dim VT1 = (From d In VehiclesTable1.AsEnumerable _
Select VehicleTypeName = d.Item("VehicleTypeName") _
, VTypeID = d.Item("VTypeID") _
, ImageURL = d.Item("ImageURL") _
, DailyRate = d.Item("DailyRate") _
, RateID = d.Item("RateID")).Distinct
its linq to dataset
and I Take Data on THis Rotator:
<telerik:RadRotator ID="RadRotatorVehicleType" runat="server" Width="620px" Height="145"
ItemWidth="155" ItemHeight="145" ScrollDirection="Left" FrameDuration="1" RotatorType="Buttons">
<ItemTemplate>
<div style="text-align: center; cursor: pointer; width: 150px">
<asp:Image ID="ImageVehicleType" runat="server" Width="150" ImageUrl='<%# Container.DataItem("ImageURL") %>' />
<asp:Label ID="lblVehicleType" runat="server" Text='<%# Container.DataItem("VehicleTypeName") %>'
Font-Bold="true"></asp:Label>
<br />
<asp:Label ID="lblDailyRate" runat="server" Text='<%# Container.DataItem("DailyRate") %>'
Visible="False"></asp:Label>
<input id="HiddenVehicleTypeID" type="hidden" value='<%# Container.DataItem("VTypeID") %>'
name="HiddenVehicleTypeID" runat="server" />
<input id="HiddenRateID" type="hidden" value='<%# Container.DataItem("RateID") %>'
name="HiddenRateID" runat="server" />
</div>
</ItemTemplate>
<ControlButtons LeftButtonID="img_left" RightButtonID="img_right" />
</telerik:RadRotator>
and I got this Exception:
No default member found for type 'VB$AnonymousType_0(Of Object,Object,Object,Object,Object)'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.MissingMemberException: No default member found for type 'VB$AnonymousType_0(Of Object,Object,Object,Object,Object)'.
I don't know whats up ?
Any help please.
Thanks for who tried to solve this
but I got solution:
using '<%# DataBinder.Eval(Container.DataItem,"ImageURL") %>'
instead of '<%# Container.DataItem("RateID") %>'
Thanks,
Thanks for who tried to solve this but I got solution:
using '<%# DataBinder.Eval(Container.DataItem,"ImageURL") %>'
instead of '<%# Container.DataItem("RateID") %>'
Thanks,

Eval ID on radiobutton in Datalist

my code gota datalist with radio button and iv made it single selectable onitemdatabound....now im trying to evaluate a hiddenfield on basis of selected radio button
my code goes like this
aspx code
<asp:DataList ID="DataList1" runat="server" RepeatColumns = "4" CssClass="datalist1"
RepeatLayout = "Table" OnItemDataBound="SOMENAMEItemBound"
CellSpacing="20" onselectedindexchanged="DataList1_SelectedIndexChanged">
<ItemTemplate>
<br />
<table cellpadding = "5px" cellspacing = "0" class="dlTable">
<tr>
<td align="center">
<a href="<%#Eval("FilePath")%>" target="_blank"><asp:Image ID="Image1" runat="server" CssClass="imu" ImageUrl = '<%# Eval("FilePath")%>'
Width = "100px" Height = "100px" style ="cursor:pointer" />
</td>
</tr>
<tr >
<td align="center">
<asp:RadioButton ID="rdb" runat="server" OnCheckedChanged="rdb_click" AutoPostBack="True" />
<asp:HiddenField ID="HiddenField1" runat="server" Value = '<%#Eval("ID")%>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
code behind
protected void SOMENAMEItemBound(object sender, DataListItemEventArgs e)
{
RadioButton rdb;
rdb = (RadioButton)e.Item.FindControl("rdb");
if (rdb != null)
rdb.Attributes.Add("onclick", "CheckOnes(this);");
}
protected void rdb_click(object sender, EventArgs e)
{
for (int i = 0; i < DataList1.Items.Count; i++)
{
RadioButton rdb;
rdb = (RadioButton)DataList1.Items[i].FindControl("rdb");
if (rdb != null)
{
if (rdb.Checked)
{
HiddenField hf = (HiddenField)DataList1.Items[i].FindControl("HiddenField1");
Response.Write(hf.Value);
}
}
}
}
the javascript im using...
function CheckOnes(spanChk){
var oItem = spanChk.children;
var theBox= (spanChk.type=="radio") ?
spanChk : spanChk.children.item[0];
xState=theBox.unchecked;
elm=theBox.form.elements;
for(i=0;i<elm.length;i++)
if(elm[i].type=="radio" &&
elm[i].id!=theBox.id)
{
elm[i].checked=xState;
}
}
iam getting an error like this
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near 'pload Demonstration|'.
is there any other way to do this or can nyone plz help to get rid of this problem
The problem is probably your Response.Write() call. Take a look at this blog post. It outlines the reasons why this particular exception shows up, and how to prevent it. Also take a look at this StackOverflow thread.
Okey lets just remove response write...now i have following in my codebehind...rest is same
label5.text=hf.value.ToString();
now i am able to evaluate Label when i use update panel nd nested updatepanel like this
<asp:UpdatePanel ID="UpdatePanel9" runat="server" >
<ContentTemplate>
<asp:DataList ID="DataList1" runat="server" RepeatColumns = "4"
CssClass="datalist1" OnItemDataBound="SOMENAMEItemBound"
CellSpacing="10" onselectedindexchanged="DataList1_SelectedIndexChanged"
HorizontalAlign="Center" Width="500px">
<ItemTemplate>
<br />
<table cellpadding = "5px" cellspacing = "0" class="dlTable">
<tr>
<td align="center">
<a href="<%#Eval("FilePath")%>" target="_blank"><asp:Image ID="Image1" runat="server" CssClass="imu" ImageUrl = '<%# Eval("FilePath")%>'
Width = "100px" Height = "100px" style ="cursor:pointer" />
</td>
</tr>
<tr >
<td align="center">
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="rdb" />
</Triggers>
<ContentTemplate>
<asp:RadioButton ID="rdb" runat="server" OnCheckedChanged="rdb_click" AutoPostBack="true" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:HiddenField ID="HiddenField1" runat="server" Value = '<%#Eval("ID")%>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</ContentTemplate>
</asp:UpdatePanel>
is there a way to to get this done without full page postback....asyncpostback trigger doesnt seem to work