I have a repeater with a chid repeater now my aim is to hide the chid repeater if the row count = 1 from its sqlDataSource, if greater i would like to show all results. i have tried
Visible='<%# ((Repeater)Container.NamingContainer).Items.Count >= 1 %>'
on the child reapter but it only works for the first iteam in my main repeater row. any suggestions
part of my code--
<div id="image_pic" ClientIDMode="Static" runat="server" >
<table style="width:100%;margin: 0 auto 0 auto">
<tr>
<td colspan="4">
<img id="mainpic" data-id='<%#"iimage"+Eval("id") %>' class="img-rounded" alt="" src='<%#Eval("ppic1") %>' style="width: 100%;max-width:550px; max-height:400px " />
</td>
</tr>
<tr><td>
<div style="padding: 3px; margin: 5px; ">
<asp:Repeater ID="Repeater2" runat="server" DataSourceID="thumbs" Visible='<%# ((Repeater)Container.NamingContainer).Items.Count >= 1 %>'><ItemTemplate>
<div id="p1" style="display: inline-block">
<img id="thumbs" alt="" class="img-rounded" src='<%#Eval("thumbs") %>' data-mainpicture='<%#Eval("Picture") %>' style="width: 80px; height: 80px; " /></div>
</ItemTemplate></asp:Repeater>
<asp:SqlDataSource ID="thumbs" runat="server" ConnectionString="<%$ ConnectionStrings:myConnection %>" SelectCommand="SELECT * FROM [ProductPictures] WHERE ([Productid] = #Productid)" >
<SelectParameters>
<asp:ControlParameter ControlID="pmap" Name="Productid" PropertyName="Value" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
My query:
SELECT Picture, Productid, thumbs
from
(
SELECT Picture, Productid, thumbs
FROM ProductPictures
GROUP BY Picture, Productid, thumbs
HAVING COUNT(Productid) <= 2
) as count
where Productid = 40
Have a sub-query that returns Productid's that have more than one picture. JOIN with that result:
SELECT Picture, Productid, thumbs
from ProductPictures p
join (SELECT Productid
FROM ProductPictures
GROUP BY Productid
HAVING COUNT(*) > 1) cnt on p.Productid = cnt.Productid
Related
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
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...
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());
}
I have a paged multicolumn ListView of items with ImageButton and LinkButton. The delete and select commands are working. I can't get the SelectedIndexChanging event to fire, and the SelectedIndex is always -1 in the Select command handler. I think I have the required select button as per the docs. My ultimate goal is to save the index of the item so when I return to the page I can restore the current ListView pager page so the selected item is visible. But I can't get the item index. This is for asp.net 4.0 webforms.
<asp:ListView ID="ListView1" runat="server" OnItemDataBound="ListView1_ItemDataBound"
DataKeyNames="ItemID" DataSourceID="ObjectDataSource1"
OnItemCommand="ListView1_ItemCommand" GroupItemCount="2"
onselectedindexchanging="ListView1_SelectedIndexChanging">
<LayoutTemplate>
<table width="100%">
<tr>
<td>
<table class="sample" width="100%">
<asp:PlaceHolder runat="server" ID="groupPlaceHolder"></asp:PlaceHolder>
</table>
</td>
</tr>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr>
<asp:PlaceHolder runat="server" ID="itemPlaceHolder"></asp:PlaceHolder>
</tr>
</GroupTemplate>
<ItemTemplate>
<td>
<asp:ImageButton ID="btnDelete" ToolTip="Delete" runat="server" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ItemID")%>' CommandName="DeleteItem" Height="12" ImageUrl="resources/delete.gif" Width="12" />
<asp:LinkButton ID="btnSelect" runat="server" CommandName="Select" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ItemID")%>'><%# DataBinder.Eval(Container.DataItem, "ItemName") %></asp:LinkButton>
<asp:Label ID="ccLabel" runat="server"></asp:Label>
</td>
</ItemTemplate>
</asp:ListView>
It would help if you posted your code (SelectedIndexChanging). But in any case, one thought:
SelectedIndexChanging won't give you the selected index, because the index hasn't actually been selected yet.
Use SelectedIndexChanged instead. This occurs after the index has been selected, so can give you a value.
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