creating grouped Repeater Layout - c#

<asp:DropDownList ID="ddlGroupSearch" CssClass="cssTextbox" runat="server">
<asp:ListItem Value="1" Text="Referring Physician Wise"></asp:ListItem>
<asp:ListItem Value="2" Text="Specialty Wise"></asp:ListItem>
</asp:DropDownList>
<asp:Repeater runat="server" ID="repeaterParent" OnItemDataBound="repeaterParent_ItemDataBound">
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblREF_PHY_ID" runat="server" Text='<%# this.RenderGroup(Eval("REF_PHY_ID") as string)%>'></asp:Label>
</td>
</tr>
<tr>
<td class="cssTableListTd">
<asp:Label ID="lblPatNameListData" runat="server" Text='<%#Eval("Patient_Name")%>'></asp:Label>
</td>
<td class="cssTableListTd">
<asp:Label ID="lblPatIDListData" runat="server" Text='<%#Eval("Patient_ID")%>'></asp:Label>
</td>
<td class="cssTableListTd">
<asp:Label ID="lblPatSexListData" runat="server" Text='<%#Eval("Sex")%>'></asp:Label>
</td>
<td class="cssTableListTd">
<asp:Label ID="lblPatBirthDateListData" runat="server" Text='<%#Eval("Patients_Birth_Date")%>'></asp:Label>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
c#
protected void Page_Load(object sender, EventArgs e)
{
//get data bind to repeater
repeaterParent.DataSource = DataTable;
repeaterParent.DataBind();.
}
string lastValue = "";
protected string RenderGroup(string currentValue)
{
if(currentValue == this.lastValue)
return "";//Group has changed
this.lastValue = currentValue;
return currentValue;
}
I have to show report group wise. I have a DropDownList in my page. Now according to the DropDownList value I have to call RenderGroup function. How should I call in repeater?
I have taken a reference of this link
ref link

Did you tried by applying group by functionality in to DataTable that you are binding to repeater?
I am pointing to something like below.
Ref: Link
Thanks!

Related

ASP.NET (C#) - ListView

In past, i worked on ListViews (.net 2.0) using a custom Template field but what i am trying to achieve here is the following
I am now working on .net 4.6
So basically a list which shows items like above and on mouse-hover few options show up as shown in the following screenshot
I also have to trigger those option to do different things -
How can I do that in asp.net, may I please have some code references.
Cheers
P.S.
This is a rough example of how i am creating the List Item Template (as requested)
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1">
<AlternatingItemTemplate>
<table >
<tr>
<td ><asp:Image ID="image1" ImageUrl='<%# Bind("url") %>' runat="server" Width="98px" /> </td>
<td><h2><asp:Label ID="_label" runat="server" Text ='<%# Bind("title") %>'></asp:Label></h2><asp:Label ID="Label1" runat="server" Text ='<%# Bind("description") %>'></asp:Label></td>
</tr>
</table>
</AlternatingItemTemplate>
<EmptyDataTemplate>
No data was returned.
</EmptyDataTemplate>
<ItemSeparatorTemplate>
<br />
</ItemSeparatorTemplate>
<ItemTemplate>
<table >
<tr>
<td ><asp:Image ID="image1" ImageUrl='<%# Bind("url") %>' runat="server" Width="98px" /> </td>
<td><h2><asp:Label ID="_label" runat="server" Text ='<%# Bind("title") %>'></asp:Label></h2><asp:Label ID="Label1" runat="server" Text ='<%# Bind("description") %>'></asp:Label></td>
</tr>
</table>
</ItemTemplate>
<LayoutTemplate>
<ul id="itemPlaceholderContainer" runat="server" style="">
<li runat="server" id="itemPlaceholder" />
</ul>
<div style="">
</div>
</LayoutTemplate>
</asp:ListView>
I can add any html formatting to this template e,g i can add ASP:button etc but i don't know how to trigger those to perform certain tasks.
One easy way to achieve your requirement is to keep those buttons there but invisible and show them up when the parent container is hovered. following as a quick sample
aspx
<asp:ListView ID="ListView1" runat="server">
<ItemTemplate>
<tr class="row-data">
<td>
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
</td>
<td>
<asp:Label ID="PositionLabel" runat="server" Text='<%# Eval("Position") %>' />
</td>
<td>
<div class="btn-area">
<asp:Button runat="server" Text="Button1" />
<asp:Button runat="server" Text="Button2" />
</div>
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="">
<th runat="server">
Name
</th>
<th runat="server">
Position
</th>
<th>
</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
css
.btn-area
{
display: none;
}
.row-data:hover .btn-area
{
display: block;
}
code-behind
protected void Page_Load(object sender, EventArgs e)
{
ListView1.DataSource = new List<dynamic>() {
new { Name = "Andy", Position = "PG"},
new { Name = "Bill", Position = "SD"},
new { Name = "Caroline", Position = "Manager"}
};
ListView1.DataBind();
}
UPDATE
ListView ItemCommand can capture the postback by button pressed and CommandName makes you able to recognize which button fired it.
<asp:Button runat="server" Text="Button1" CommandName="c1" />
<asp:Button runat="server" Text="Button2" CommandName="c2" />
code-behind
protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
{
if (e.CommandName == "c1")
{
// do something when button1 pressed
}
else if (e.CommandName == "c1")
{
// do something when button2 pressed
}
}

In Paged Listview CheckBox_CheckedChanged event not working

The Problem is when I check the checkbox it works great, but when I check the checkbox on next page. previous page check boxes gets unchecked.
Checked box Checked/Unchecked event fires CheckedChanged event. But when I check the checkbox in listview next page of listview it uncheck's the checkboxes of listview previous Page.
ListView.aspx Code
<table class=" example1 table table-bordered table-striped">
<thead>
<tr>
<th>Sr no.</th>
<th>Parent Category</th>
<th>Title</th>
<th>Description</th>
<th>Image</th>
<th>Show on Homepage</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<asp:ListView ID="ListCourse" runat="server" OnItemCommand="ListCourse_ItemCommand" DataKeyNames="CID">
<LayoutTemplate>
<tr id="ItemPlaceholder" runat="server">
</tr>
</LayoutTemplate>
<ItemTemplate>
<tr class="gradeA">
<td>
<asp:Label ID="lblSrno" runat="server" Text='<%# Container.DataItemIndex+1 %>'></asp:Label>
</td>
<td>
<asp:Label ID="lbl" runat="server" Text='<%# GetCourse(Convert.ToInt32( Eval("CatID"))) %>'></asp:Label>
</td>
<td>
<asp:Label ID="Lbltitle" runat="server" Text='<%# Eval("Title") %>'></asp:Label>
<asp:Label ID="lablc" runat="server" Visible="false" Text='<%# Eval("CID") %>'></asp:Label>
</td>
<td>
<asp:Label ID="lblDescrption" runat="server" Text='<%# (Eval("Description").ToString().Length <=200)?Eval("Description").ToString(): Eval("Description").ToString().Substring(0, 200) + "..."%>'></b></asp:Label>
</td>
<td>
<img class="img_show " src="/Gallery/<%# Eval("Image")%>">
</td>
<td>
<asp:CheckBox ID="CheckCourse" runat="server" Style="margin-left: 50px;" OnCheckedChanged="CheckCourse_CheckedChanged" AutoPostBack="true" />
</td>
<td>
<asp:LinkButton ID="LinkEdit" runat="server" PostBackUrl='<%# "Add_New_Course.aspx?ID="+ Eval("CID")%>'>Edit</asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="LinkDelete" runat="server" CommandName="DeleteCourse" CommandArgument='<%# Eval("CID") %>' OnClientClick='return confirm("Do you want to delete record ??")'> Delete</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
</tbody>
</table>
Code Behind CheckedChanged
protected void CheckCourse_CheckedChanged(object sender, EventArgs e)
{
CheckBox checkhome = (CheckBox)sender;
ListViewItem item = (ListViewItem)checkhome.NamingContainer;
ListViewDataItem dataItem = (ListViewDataItem)item;
string code = ListCourse.DataKeys[dataItem.DisplayIndex].Value.ToString();
int CID = Convert.ToInt32(code);
Course_Master objnew = DB.Course_Master.Single(p => p.CID == CID);
bool IsHome = CheckOnHome(CID);
if (IsHome == true)
{
if (checkhome.Checked == false)
{
objnew.ShowOnHomePage = false;
}
}
else
{
if (checkhome.Checked == true)
{
objnew.ShowOnHomePage = true;
}
}
DB.SaveChanges();
}
It doesn't fire because when the postback fires the server doesn't know the previous state of the checkbox, so it doesn't know if it's changed or not.
Try to set the default value to false and it should work
<asp:CheckBox ID="CheckCourse" runat="server" Checked="false" Style="margin-left: 50px;" OnCheckedChanged="CheckCourse_CheckedChanged" AutoPostBack="true" />
You need to save ids somewhere of checked item from the list. As when you move to the page 2 of ListView it lost its previous state.
Store data in viewstate and load it from there. To read and to bind it, you would need to handle PagePropertiesChanging and ItemDataBound event handlers of ListView.
Here is a good explaination regarding Maintaining the state of checkboxes in ListView
Please give +1 if it helped. Cheers!
Thank you Guys for the help. I solved it using some simple procedure's by removing the check-boxes from the ListView and adding text instead of it regarding whether the checkbox is checked or not(Yes/No). As I thought it will the easiest way to solve my problem.

Checkbox state not changed on postback

I have the following mark up for a User Control (.ascx)
<table>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Select Logical Symbol to Search:"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlComponentType" runat="server"
onselectedindexchanged="ddlComponentType_SelectedIndexChanged" AutoPostBack="true">
</asp:DropDownList>
</td>
<td>
<asp:CheckBox ID="chkAdvSearchAllLibs" runat="server" ToolTip="Check this box to search all available libraries" Text="Search All Libraries"/>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="Search by Logical Symbol Properties:"></asp:Label>
</td>
<td>
</td>
</tr>
On page Load
protected void Page_Load(object sender, EventArgs e)
{
SearchResults(ref attributeSearch, compTypeID);
}
where SearchResults is
private void SearchResults(ref string attributeSearch, int compTypeID)
{
DataTable dtResults = this.AdvancedSearchControl.GetSearchResults(ref attributeSearch, compTypeID);
}
And in my UserControl.ascx.cs
public DataTable GetSearchResults(ref string _attrVals, int compTypeID)
{
//Other Logic Goes Here
IEnumerable<Model.ComponentInfo.ComponentType> compTypeResult = from compTypes in BLLibrary.GetComponentTypeBasedOnLib(this.CurrentLibraryId, this.CurrentLibrary, this.chkAdvSearchAllLibs.Checked) select compTypes.Value;
}
this.chkAdvSearchAllLibs.Checked is always false no matter if the check-box is checked on page and posted back or not.
Server side:
Add AutoPostBack="True" to the CheckBox. It's not posting back.
Client side:
<asp:CheckBox runat="server" ID="cb" onclick="checkboxchanged(this);" />
function checkboxchanged( sender ) {
if ( sender.checked ) {
// clicked and checked
} else {
// clicked and unchecked
}
}

DataList is not binding event after datatable is correct

I have following datalist:
<asp:DataList ID="dlOrgImages" runat="server"
Width="100%" RepeatColumns="4" RepeatDirection="Horizontal">
<ItemTemplate>
<table width="98%">
<tr>
<td>
<asp:Image ID="imgLogo" ImageUrl='OrgImages/<%# Eval("Logo") %>' runat="server" />
</td>
</tr>
<tr>
<td>
<asp:RadioButton ID="rdLogoSelect" runat="server" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
I am binding it through code:
private void BindOrgLogo()
{
dlOrgImages.DataSource= obj.GetDataTable("select idOrg,Title,Logo from Organization order by idOrg");
dlOrgImages.DataBind();
}
obj.GetDataTable(...) is giving me correct datatable.
But datalist is not getting bound. Its not showing me anything.
What can be the problem???
Please help me.

Hide RadGrid EditFormSettings control runtime

Below is my code for a RadGrid edit form, and it's working fine but I want to hide place holder control ID="plupload" on Insert/Edit mode of EditFormSettings on RadComboBox1 index changed event.
Can anyone please help to fix this issue?
<editformsettings editformtype="Template">
<FormTemplate>
<table id="Table2" cellspacing="2" cellpadding="1" width="100%" border="0" rules="none" style="border-collapse: collapse;">
<tr>
<td>
<table id="Table4" cellspacing="1" cellpadding="1" width="50%" border="0" class="module">
<tr>
<td>
Name:
</td>
<td>
<asp:TextBox ID="TextBox2" Text='<%# Bind( "Name") %>' runat="server" TabIndex="8">
</asp:TextBox>
</td>
</tr>
<asp:PlaceHolder ID="plupload" runat="server" >
<tr>
<td>
File Upload :
</td>
<td>
<telerik:RadAsyncUpload runat="server" ID="AsyncUpload1" OnClientFileUploaded="OnClientFileUploaded" MultipleFileSelection="Disabled" AllowedFileExtensions="jpg,jpeg,png,gif" MaxFileSize="1048576" onvalidatingfile="RadAsyncUpload1_ValidatingFile">
</telerik:RadAsyncUpload>
</td>
</tr>
</asp:PlaceHolder>
</table>
</td>
<td>
</td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'></asp:Button>
<asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel"></asp:Button>
</td>
</tr>
</table>
</FormTemplate>
</editformsettings>
Here is my RadComboBox code:
<telerik:RadComboBox ID="RadComboBox1" runat="server" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged" AutoPostBack="True">
<Items>
<telerik:RadComboBoxItem Value="1" Text="Show All" />
<telerik:RadComboBoxItem Value="2" Text="Hide File Upload" />
</Items>
</telerik:RadComboBox>
Since you did not mention where your RadComboBox is, I am assuming it is outside of the RadGrid control. If that is the case, I suggest you implement a custom method to recursively search for your Placeholder.
// search for a specified control in the given root control and all its children
public static Control FindControlRecursive(Control rootControl, string searchControlID)
{
if (rootControl.ID == searchControlID) return rootControl;
foreach (Control controlToSearch in rootControl.Controls)
{
Control controlToReturn = FindControlRecursive(controlToSearch, searchControlID);
if (controlToReturn != null) return controlToReturn;
}
return null;
}
Then, in your page's code-behind, you can search for plupload and set its Visible attribute.
protected void RadComboBox1_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e))
{
RadComboBox RadComboBox1 = (RadComboBox)sender;
// Get the placeholder control nested inside the RadGrid
Placeholder plupload = (Placeholder)FindControlRecursive(RadGrid1, "plupload");
if (plupload != null)
{
if (RadComboBox1.SelectedValue == "2")
plupload.Visible = false;
else plupload.Visible = true;
}
}

Categories

Resources