How to Fix Header and Sub-Header in Repeater in ASP.NET - css

How to fix header and sub-Header when scroll-up or down of Repeater i am trying with CSS (style) Ref. link(https://www.aspdotnet-suresh.com/2015/03/aspnet-scrollable-repeater-control-with-fixed-column-header-using-css-in-csharp-vbnet.html) and that is work properly for single header but not for sub-header, is there any way to do this?
Repeater
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
$("table").prepend("<tr style=' color: white; background-color: #9494b9;'> <th>Column 1</th><th colspan='2'>Column 2</th><th colspan='2'>Column 3</th></tr>")
})
</script>
<style type="text/css">
#rpttable tr td
{
max-height:10%;
}
table {
border-collapse: collapse;
text-align: center;
}
</style>
<asp:Repeater ID="rptDrugs" runat="server" >
<HeaderTemplate>
<table border="1" id="rpttable">
<tr style=" color: white; background-color: #9494b9;">
<th scope="col" style="width: 80px"> </th>
<th scope="col" style="width: 80px">Dosage
</th>
<th scope="col" style="width: 120px">Drug
</th>
<th scope="col" style="width: 100px">Patient
</th>
<th scope="col" style="width: 100px">Date
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="" />
</td>
<td>
<asp:Label ID="lblCustomerId" runat="server" Text='<%# Eval("Dosage") %>' />
</td>
<td>
<asp:Label ID="lblContactName" runat="server" Text='<%# Eval("Drug") %>' />
</td>
<td>
<asp:Label ID="lblCountry" runat="server" Text='<%# Eval("Patient") %>' />
</td>
<td>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Date") %>' />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
CS
protected void Page_Load(object sender, EventArgs e)
{
DataTable table = new DataTable();
table.Columns.Add("Dosage", typeof(int));
table.Columns.Add("Drug", typeof(string));
table.Columns.Add("Patient", typeof(string));
table.Columns.Add("Date", typeof(DateTime));
// Here we add five DataRows.
table.Rows.Add(25, "Indocin", "David", DateTime.Now);
table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);
rptDrugs.DataSource = table;
rptDrugs.DataBind();
}

Related

asp.net TextBox not updating in IE11

I have migrated my .net projet from framework 3.5 to 4.5 and my the site was previously running under IE7.
I need to run it under IE11 now. I have a page which upon selecting an element in a dropdown display the values of the element selected.
The element has 3 different fields:
Code, name and info et a button delete which upon clicking delete the element and empty the fields.
Below is the code which does the reset:
protected void LB_Supprimer_Click(object sender, System.EventArgs e)
{
if ( this.DBDelete_TRF() )
{
this.TB_NOM.Text = "" ;
this.TB_CODE.Text = "" ;
this.TB_ACTCORR.Text = "" ;
}
MngMessage.refresh();
}
Code in aspx:
<TABLE id="Table1" borderColor="lightgrey" cellSpacing="5" cellPadding="0" width="100%"
border="0">
<TR>
<TD style="WIDTH: 168px; HEIGHT: 19px" align="right">
<asp:Label id="Lbl_code" runat="server" CssClass="label" DESIGNTIMEDRAGDROP="47">Code : </asp:Label></TD>
<TD style="WIDTH: 403px; HEIGHT: 19px">
<asp:TextBox id="TB_CODE" runat="server" Width="96px" CssClass="txt" DESIGNTIMEDRAGDROP="73"
ToolTip="Code" Font-Bold="True" ontextchanged="TB_CODE_TextChanged"></asp:TextBox>
</TD>
</TR>
<TR>
<TD style="WIDTH: 168px; HEIGHT: 68px" align="right">
<asp:Label id="Label_Nom" runat="server" CssClass="label" DESIGNTIMEDRAGDROP="86">Nom : </asp:Label></TD>
<TD style="WIDTH: 403px; HEIGHT: 68px">
<asp:TextBox id="TB_NOM" runat="server" Height="54px" Width="360px" CssClass="txt" DESIGNTIMEDRAGDROP="85"
Font-Bold="True" TextMode="MultiLine" Rows="4"></asp:TextBox></TD>
</TR>
<TR>
<TD style="WIDTH: 168px" align="right"></TD>
<TD style="WIDTH: 403px">
<asp:Label id="LB_INFO" runat="server" CssClass="label">Info</asp:Label></TD>
</TR>
<TR>
<TD style="WIDTH: 168px" align="right">
<asp:Label id="Label8" runat="server" CssClass="label" DESIGNTIMEDRAGDROP="49">Action : </asp:Label>
<asp:CheckBox id="chk_Confirmee" runat="server" CssClass="DBLabel" ToolTip="xxx yyy"
Text="Confirmée"></asp:CheckBox></TD>
<TD style="WIDTH: 403px">
<asp:TextBox id="TB_ACTCORR" runat="server" Height="74px" Width="360px" CssClass="txt" TextMode="MultiLine"
Rows="5"></asp:TextBox></TD>
</TR>
<TR>
<TD align="center" height="15"><cc1:linkbutton id="LB_Supprimer" runat="server" DisableText="Traitement en cours" DisableAfterClick="True" onclick="LB_Supprimer_Click">Supprimer</cc1:linkbutton></TD>
</TR>
</TABLE>
The above does not work in IE11 only but in chrome it does.
Any idea how to solve this pls?

Changing style conditionally on a ListView based on value in another column

I am trying to change the background color on a row if the absolute value of an added column in a table is less than 8. I have tried several different ways, but the latest attempt, although seemingly close, does not perform as I expected.
<asp:ListView ID="ListView2" runat="server" >
<LayoutTemplate>
<table id="Table2" style="border:solid" runat="server">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table runat="server" id="itemPlaceholderContainer" border="0" >
<tr id="Tr2" runat="server" style='<%# Eval("Alert") %>'>
<th id="Th1" runat="server">Date</th>
<th id="Th2" runat="server">Home</th>
<th id="Th3" runat="server">Score</th>
<th id="Th4" runat="server">Away</th>
<th id="Th5" runat="server">Score</th>
<th id="Th6" runat="server">Quarter</th>
<th id="Th7" runat="server">Link To Game</th>
<th id="Th8" runat="server"></th>
</tr>
<tr runat="server" id="itemPlaceholder"></tr>
</table>
</td>
</tr>
<tr id="Tr3" runat="server">
<td id="Td2" runat="server" style=""></td>
</tr>
</table>
</LayoutTemplate>
<AlternatingItemTemplate>
<tr style="">
<td style="border:solid">
<asp:Label Text='<%# Eval("Date") %>' runat="server" ID="DateLabel2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("HighSchoolName") %>' runat="server" ID="HighSchoolNameLabel2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("HomeTeamScore") %>' runat="server" ID="HomeTeamScoreLabel2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("HighSchoolName1") %>' runat="server" ID="HighSchoolName1Label2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("AwayTeamScore") %>' runat="server" ID="AwayTeamScoreLabel2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("Quarter") %>' runat="server" ID="LabelQuarter" /></td>
<td style="border:solid" id="HomeAudioLink">
<a href="<%# Eval("AudioInternetLink") %>" target="_blank" >
<asp:Label Text='<%# Eval("AudioInternetLink") %>' runat="server" ID="LabelHomeAudioLink" />
</a>
</td>
<td style="border:solid" id="AwayAudioLink">
<a href="<%# Eval("AudioInternetLink1") %>" target="_blank" >
<asp:Label Text='<%# Eval("AudioInternetLink1") %>' runat="server" ID="LabelAwayAudioLink" />
</a>
</td>
</tr>
</AlternatingItemTemplate>
<EmptyDataTemplate>
<table id="Table1" runat="server" style="">
<tr>
<td>No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<ItemTemplate>
<tr id="Game" style="" runat="server" class="" >
<td style="border:solid">
<asp:Label Text='<%# Eval("Date") %>' runat="server" ID="DateLabel2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("HighSchoolName") %>' runat="server" ID="HighSchoolNameLabel2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("HomeTeamScore") %>' runat="server" ID="HomeTeamScoreLabel2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("HighSchoolName1") %>' runat="server" ID="HighSchoolName1Label2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("AwayTeamScore") %>' runat="server" ID="AwayTeamScoreLabel2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("Quarter") %>' runat="server" ID="LabelQuarter" /></td>
<td style="border:solid" id="HomeAudioLink">
<a href="<%# Eval("AudioInternetLink") %>" target="_blank" >
<asp:Label Text='<%# Eval("AudioInternetLink") %>' runat="server" ID="LabelHomeAudioLink" />
</a>
</td>
<td style="border:solid" id="AwayAudioLink">
<a href="<%# Eval("AudioInternetLink1") %>" target="_blank" >
<asp:Label Text='<%# Eval("AudioInternetLink1") %>' runat="server" ID="LabelAwayAudioLink" />
</a>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
And the C# code:
protected void ScheduleButton_Click(object sender, EventArgs e)
{
/**********************************************************************/
/* The code below will initialize the connection to the database. */
/* As the connection string to the SQL database is defined as conn, */
/* the open method from conn will connect to the database, and the */
/* cmd variable will call on the stored procedure GetSchedule. */
/**********************************************************************/
string strcon = WebConfigurationManager.ConnectionStrings["FollowingHSFootballConnectionString"].ConnectionString;
using (SqlConnection conn = new SqlConnection(strcon))
{
SqlCommand cmd = new SqlCommand("CurrentSchedScore", conn);
cmd.CommandType = CommandType.StoredProcedure;
conn.Open();
DataTable ScheduleTbl = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
// Fill the partial DataSet into a partial DataTable.
da.Fill(ScheduleTbl);
ListView2.DataSource = ScheduleTbl;
ListView2.DataBind();
// Close Game Logic
ScheduleTbl.Columns.Add("Diff", typeof(int), "HomeTeamScore - AwayTeamScore");
ScheduleTbl.Columns.Add("Alert", typeof(string), "");
for (int i = 0; i < ScheduleTbl.Rows.Count; i++)
{
DataRow drST = ScheduleTbl.Rows[i];
if (Math.Abs((int)drST.ItemArray.GetValue(8)) <= 8)
{
drST.BeginEdit();
drST.ItemArray.SetValue("background-color:red", 9);
drST.AcceptChanges();
drST.EndEdit();
}
}
}
}
Where did I misunderstand how to update the last column?
I found that I had to use a javascript solution that worked.
#Class = ClassSchedDropDown.SelectedValue;
if (RegionSchedDropDown.SelectedValue == "")
{
for (int i = 1; i <= 8; i++)
{
SchedScoreDirect = "CurrentSchedScoreClassReg";
#Reg = i;
}
}
The SchedScoreDirect = "CurrentSchedScoreClassReg code will direct processing to send the red background to the appropriate row.

Listview is losing data on postback ASP.Net

I am trying to update the whole list by once by using a button but in code behind I am losing the data of the list items it returns null although it has the items. Please help me in this manner. my code is below
aspx
<asp:ListView ID="ProjectsList" runat="server" DataKeyNames="ProjectId" DataSourceID="EntityDataSource1" ViewStateMode="Enabled">
<AlternatingItemTemplate>
<tr style="background-color: #FFF8DC;">
<td><asp:Label ID="ProjectIdLabel" runat="server" Text='<%# Eval("ProjectId") %>' /></td>
<td><asp:Label ID="SchoolIdLabel" runat="server" Text='<%# Eval("SchoolId") %>' /></td>
<td><asp:Label ID="FairIdLabel" runat="server" Text='<%# Eval("FairId") %>' /></td>
<td><asp:Label ID="CategoryIdLabel" runat="server" Text='<%# Eval("CategoryId") %>' /></td>
<td><asp:Label ID="TitleLabel" runat="server" Text='<%# Eval("Title") %>' /></td>
<td><asp:Label ID="BalanceLabel" runat="server" Text='<%# Eval("Balance") %>' /></td>
<td><asp:CheckBox ID="FinalistCheckBox" runat="server" Checked='<%# Eval("Finalist") %>' Enabled="true" /></td>
<td><asp:Label ID="ProjectStatusLabel" runat="server" Text='<%# Eval("ProjectStatus") %>' /></td>
</tr>
</AlternatingItemTemplate>
<ItemTemplate>
<tr style="background-color: #DCDCDC; color: #000000;">
<td><asp:Label ID="ProjectIdLabel" runat="server" Text='<%# Eval("ProjectId") %>' /></td>
<td>asp:Label ID="SchoolIdLabel" runat="server" Text='<%# Eval("SchoolId") %>' /></td>
<td><asp:Label ID="FairIdLabel" runat="server" Text='<%# Eval("FairId") %>' /></td>
<td><asp:Label ID="CategoryIdLabel" runat="server" Text='<%# Eval("CategoryId") %>' /></td>
<td><asp:Label ID="TitleLabel" runat="server" Text='<%# Eval("Title") %>' /></td>
<td><asp:Label ID="BalanceLabel" runat="server" Text='<%# Eval("Balance") %>' /></td>
<td><asp:CheckBox ID="FinalistCheckBox" runat="server" Checked='<%# Eval("Finalist") %>' Enabled="true" /></td>
<td><asp:Label ID="ProjectStatusLabel" runat="server" Text='<%# Eval("ProjectStatus") %>' /></td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table id="itemPlaceholderContainer" runat="server" border="1" style="background-color: #FFFFFF; border-collapse: collapse; border-color: #999999; border-style: none; border-width: 1px; font-family: Verdana, Arial, Helvetica, sans-serif;">
<tr runat="server" style="background-color: #DCDCDC; color: #000000;">
<th runat="server">ProjectId</th>
<th id="Th1" runat="server">SchoolId</th>
<th id="Th2" runat="server">FairId</th>
<th id="Th3" runat="server">CategoryId</th>
<th runat="server">Title</th>
<th id="Th4" runat="server">Balance</th>
<th runat="server">Finalist</th>
<th runat="server">ProjectStatus</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="text-align: center; background-color: #CCCCCC; font-family: Verdana, Arial, Helvetica, sans-serif; color: #000000;"></td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
<asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=MyEntity" DefaultContainerName="MyEntity" EnableFlattening="False" EnableUpdate="True" EntitySetName="Projects">
</asp:EntityDataSource>
<asp:Button ID="FinalistButton" runat="server" Text="Finalist" OnClick="FinalistButton_Click" CssClass="imageButtonStyle" />
and my aspx.cs...
protected void FinalistButton_Click(object sender, EventArgs e)
{
//here I can have all the items but there is no value
foreach (ListViewItem item in ProjectsList.Items)
{
if (item.ItemType == ListViewItemType.DataItem)
{
CheckBox final = (CheckBox)item.FindControl("Finalist");
TextBox proidText = (TextBox)item.FindControl("ProjectId");
int proId = Convert.ToInt32(proidText.Text);
if (final.Checked)
{
//some code
}
}
}
}
To insert or update data, the templates < InsertItemTemplate> and/or < EditItemTemplate> should be included, maybe they're missing. Templates < ItemTemplate> and < AlternateItemTemplate> are just used to show data. To change templates, add some command buttons. And you use Bind instead of Eval
You have a walkthrough at the following link, not very good, though. Maybe you can find a better example.
http://msdn.microsoft.com/en-us/library/bb515103.aspx

how to bind string[] array to only one column of listview

select | Application No.
There are two columns in my listview(generated by following code) where 1st column is select link while other is simple column with header application number (header shown above):
<asp:ListView ID="ListBox1" runat ="server" AutoPostBack="True"
onselectedindexchanged="ListBox1_SelectedIndexChanged">
<LayoutTemplate>
<table style="border: solid 2px #336699;" cellspacing="0" cellpadding="3" rules="all">
<tr style="background-color: #336699; color: White;">
<th>Select</th>
<th>Application No.</th>
</tr>
<tbody>
<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
</tbody>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<asp:LinkButton ID="lnkSelect" Text="Select" CommandName="Select" runat="server" />
</td>
<td><%# Container.DataItem %></td>
</tr>
</ItemTemplate>
<SelectedItemTemplate>
<tr style="background-color: #336699; color: White;">
<td>
<asp:LinkButton ID="lnkSelect" Text="Select" CommandName="Select" runat="server"
ForeColor="White" />
</td>
<td><%# Container.DataItem %></td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
now i want to display application number from string[] array. How i can do that plz help..?
//are you using datatable as datasource?, if so
var arr = new[] { "one", "two" };
var dt = new DataTable();
dt.Columns.Add("ApplicationNo", typeof(string));
var i = 0;
foreach (DataRow dr in dt.Rows)
{
dr["ApplicationNo"] = arr[i];
dt.AcceptChanges();
i++;
}
ListBox1.DataSource=dt;
ListBox1.DataBind();
Try this,
<asp:ListView ID="mylist" runat="server"
onselectedindexchanged="mylist_SelectedIndexChanged">
<LayoutTemplate>
<table style="border: solid 2px #336699;" cellspacing="0" cellpadding="3" rules="all">
<tr style="background-color: #336699; color: White;">
<th>
Select
</th>
<th>
Application No.
</th>
</tr>
<tbody>
<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
</tbody>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<asp:LinkButton OnClick="lnkSelect_OnClick" ID="lnkSelect" Text="Select" CommandArgument='<%# Container.DataItem %>' CommandName="Select" runat="server" />
</td>
<td>
<%# Container.DataItem %>
</td>
</tr>
</ItemTemplate>
<SelectedItemTemplate>
<tr style="background-color: #336699; color: White;">
<td>
<asp:LinkButton ID="lnkSelect" Text="Select" CommandName="Select" runat="server"
ForeColor="White" />
</td>
<td>
<%# Container.DataItem %>
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
IList<string> myList = new List<string>();
myList.Add("1");
myList.Add("3");
myList.Add("2");
myList.Add("4");
mylist.DataSource = myList;
mylist.DataBind();
OR
string[] myList = new string[] { "1","2","3" };
mylist.DataSource = myList;
mylist.DataBind();
protected void lnkSelect_OnClick(object sender, EventArgs e)
{
string val = ((System.Web.UI.WebControls.LinkButton)(sender)).CommandArgument;
}

How to manipulate the value in Listview itemtemplate, returned by sqldatasource?

I have a listview and a label in the ItemTemplate, i have set the text to
<asp:Label id="GreenDate" runat="server" Text='<%# Eval("NewsDate") %>'></asp:Label>
but i want to manipulate the value returned by datasource,which is Eval("NewsDate") and show the new value in the label.
in which event i can access this value and how?
protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
HtmlTableCell lblpwdHeader = (HtmlTableCell)this.ListView1.FindControl("tdColumn");
HtmlTableCell tdPwdData = (HtmlTableCell)e.Item.FindControl("tdPwd");
if (lblpwdHeader != null)
{
lblpwdHeader.Visible = false;
}
if (tdPwdData != null)
{
tdPwdData.Visible = false;
}
}
}
============
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" OnItemDataBound="ListView1_ItemDataBound">
<LayoutTemplate>
<table border="0" cellpadding="1" width="50%">
<tr style="background-color: #E5E5FE">
<th style="width: 30%">
<asp:LinkButton ID="lnkId" runat="server" CommandName="Sort" CommandArgument="ID">Id</asp:LinkButton>
</th>
<th style="width: 40%">
<asp:LinkButton ID="lnkName" runat="server" CommandName="Sort" CommandArgument="UserName">Name</asp:LinkButton>
</th>
<th id="tdColumn" runat="server" style="width: 30%">
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Sort" CommandArgument="Password">Password</asp:LinkButton>
</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<table border="0" cellpadding="1" cellspacing="2" width="50%">
<tr>
<td style="width: 30%; text-align: center">
<asp:Label runat="server" ID="lblId"><%#Eval("ID") %></asp:Label>
</td>
<td style="width: 40%; text-align: center">
<asp:Label runat="server" ID="lblName"><%#Eval("UserName")%></asp:Label>
</td>
<td id="tdPwd" runat="server" style="width: 30%; text-align: center">
<asp:Label ID="lblPwd" runat="server"><%#Eval("Password")%></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
<AlternatingItemTemplate>
<table border="0" cellpadding="1" cellspacing="2" width="50%">
<tr>
<td style="width: 30%; text-align: center">
<asp:Label runat="server" ID="lblId"><%#Eval("ID") %></asp:Label>
</td>
<td style="width: 40%; text-align: center">
<asp:Label runat="server" ID="lblName"><%#Eval("UserName")%></asp:Label>
</td>
<td id="tdPwd" runat="server" style="width: 30%; text-align: center">
<asp:Label ID="lblPwd" runat="server"><%#Eval("Password")%></asp:Label>
</td>
</tr>
</table>
</AlternatingItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestAshokConnectionString %>"
SelectCommand="SELECT * FROM [Users]"></asp:SqlDataSource>
Use the following Event: ItemDataBound, and use DataBinder.Eval(e.Item.DataItem, "NewsDate") which is equivalent to this <%# Eval("NewsDate") %>.
Here's the syntax to get the Label Control:
Label lbl = (Label) Item.Controls.FindControlByID("GreenDate");

Resources