I'm trying to implement this algorith in a View page using Razor, but, it does not display the expected result and I don't get any compilation errors. Any suggestion please ?
Edit : I apologize I was not very clear, I confess. My problem is that I do not understand why ViewBag.NbrePages is equal to 0. However, the database had been filled.
Action();
[HttpGet]
public ActionResult Rechercher(string rech, string type, int num = 1)
{
int nbLignesDepassees = 10 * (num - 1);
ViewBag.Recherche = Server.HtmlEncode(rech);
ViewBag.Type = Server.HtmlEncode(type);
ViewBag.NumPgeCourrante = num;
if (type == "nomAppMetier")
{
var appsMetiers = _db.AppsMetiers
.Where(x => SqlFunctions.PatIndex("%" + rech + "%", x.nomApplication) > 0)
.OrderBy(x => x.nomApplication)
.Skip(nbLignesDepassees)
.Take(10);
ViewBag.NbrePages = (int)(appsMetiers.Count() / 10) ;
return View("RechercheAppsMetiers",appsMetiers);
}
if (type == "nomPoste")
{
var postes = _db.Postes
.Where(x => SqlFunctions.PatIndex("%" + rech + "%", x.nomPoste) > 0)
.OrderBy(x => x.nomPoste)
.Skip(nbLignesDepassees)
.Take(10);
ViewBag.NbrePages = (int)(postes.Count() / 10);
return View("RecherchePostes", postes);
}
return HttpNotFound();
}
View();
<ul>
#{
for (int i = 0; i < ViewBag.NbrePages; i++)
{
if(i==1 || i==2 || i==3){
<li class="disabled">&maquo;</li>
}else{
<li>«</li>
}
if (i == ViewBag.NumPgeCourrante)
{
<li class="active">#i <span class="sr-only">(current)</span></li>
}
else
{
<li>#i </li>
}
if(i==ViewBag.NbrePages || i==ViewBag.NbrePages-1 || i==ViewBag.NbrePages-2){
<li class="disabled">»</li>
}else{
<li>»</li>
}
}
}
</ul>
Thanks a lot !
Rather than having so much logic in the view, consider the following:
A model
public class PagesModel
{
public int NumberOfPages { get; set; }
public int CurrentPage { get; set; }
}
A helper method in a class
public static class Helpers
{
public static bool GetClassNames(int page, int totalPages, int currentPage)
{
var classNames = new List<string>();
var isWithinFirstOrLastThree = page <= 2 || page >= (totalPages - 2);
if (isWithinFirstOrLastThree)
{
classNames.Add("disabled");
}
if (page == currentPage)
{
classNames.Add("active");
}
return string.Join(" ", classNames.ToArray());
}
}
And then your view could be as simple as
#model PagesModel
#for (int i = 0; i < Model.NumberOfPages; i++)
{
<li class="#Helpers.GetClassNames(i, Model.NumberOfPages, Model.CurrentPage)">
&maquo;
#i
</li>
}
This doesn't exactly match what you are trying to achieve, but I hope that it is helpful nonetheless.
NbrePages will be either 0 or 1 (if you have more that 10 records) due to Take(10) and using integer division:
ViewBag.NbrePages = (int)(appsMetiers.Count() / 10) ;
So most likely you get less that 10 items in appsMetiers.
Suggestion to improve source based on original misspelling of the variable in CSHTM:
Using good names or strongly typed model would help to avoid spelling like NbrePges in for condition in original post:
for (int i = 0; i < ViewBag.NbrePages; i++)
CSHTML files are not compiled till run-time access, so no compile errors. Since ViewBag allows any property to be used you are not getting any intellisense warning either.
Instead of ViewBag consider some strongly typed model or at least put strongly typed object for paging into ViewBag:
class PagingState
{
public int NumberOfPages { get;set;}
public int CurrentPage { get;set;}
}
and in view:
var pageingState = (PagingState)(ViewBag.Paging);
for(int I = 0; i < pageingState.NumberOfPages; i++)...
Related
I have a simple class called Team, that looks like this:
public class Team
{
public Team ParentTeam;
public string Name;
}
So it has a Name and a reference to another team that is its Parent Team.
I now have a list of Teams that I am getting back from a function
List<Team> list = GetTeamsList();
Given, a few assumptions:
All teams have a ParentTeam except one (the top team)
Every team returned in the list is part of the same hierarchy and its only a single hierarchy (no 2 teams at the same "level")
I now need to take the results of this function and order the list by the hierarchy
So imagine we have the following team information:
|| Team Name || Parent Team Name ||
||-----------||------------------||
|| Team A || Team B ||
|| Team B || Team C ||
|| Team C || Team D ||
|| Team D || null ||
but the GetTeamsList() function returns the teams in any random order. For example, it might come back list this:
var teamA = GetTeamA();
var teamB = GetTeamB();
var teamC = GetTeamC();
var teamD = GetTeamD();
List<Team> list = new List() { teamD, teamA, teamB, teamC };
where I need to reorder this list so it looks like this:
List<Team> list = new List() { teamA, teamB, teamC, teamD };
How could I reorder a list into the "correct" order based on the team hierarchy?
Several of the solutions given so far are correct, and all of them are at least quadratic in the number of teams; they will be inefficient as the number of teams grows large.
Here's a solution which is (1) linear, (2) shorter, and (3) easier to understand than some of the other solutions so far:
static IEnumerable<Team> SortTeams(IEnumerable<Team> teams)
{
var lookup = teams.ToDictionary(t => t.ParentTeam ?? new Team());
var current = teams.Single(t => t.ParentTeam == null);
do
yield return current;
while (lookup.TryGetValue(current, out current));
}
This produces the sequence in the reverse of the order you want, so put a Reverse on the end of the call if you want it in the other order:
Console.WriteLine(String.Join(" ", SortTeams(teams).Reverse().Select(t => t.Name)));
The "dummy" team is there because a dictionary does not allow a key to be null.
This is my suggestion:
public class Team
{
public Team ParentTeam;
public string Name;
int Level
{
get
{
int i = 0;
Team p = this.ParentTeam;
while (p != null)
{
i++;
p = p.ParentTeam;
}
return i;
}
}
static IEnumerable<Team> Sort(IEnumerable<Team> list)
{
return list.OrderBy(o => o.Level);
}
}
Of course, if there are Teams with equal level, you might use another criteria to sort them.
This should work:
static IEnumerable<Team> GetOrdered(IEnumerable<Team> teams)
{
var set = teams as HashSet<Team> ?? new HashSet<Team>(teams);
var current = teams.First(t => t.Parent == null);
while (set.Count > 1)
{
yield return current;
set.Remove(current);
current = set.First(t => t.Parent == current);
}
yield return set.Single();
}
This gives you the reversed order, so you should call Reverse() to get the order you are asking for.
We can find the ascendants of the null team, defining an extension
public static IEnumerable<Team> FindAscendants(this IEnumerable<Team> l, Team from)
{
Team t = l.FirstOrDefault(x =>
(x.ParentTeam?.Name ?? "").Equals(from?.Name ?? ""));
return new List<Team>() { t }.Concat(t != null ?
l.FindAscendants(t) : Enumerable.Empty<Team>());
}
and reverse the order of the null team's ascendants
list.FindAscendants(null).Reverse().Skip(1)
Edit
Alternative version of the extension with yield return
public static IEnumerable<Team> FindAscendants(this IEnumerable<Team> l, Team from)
{
Team t = l.FirstOrDefault(x =>
(x.ParentTeam?.Name ?? "").Equals(from?.Name ?? ""));
yield return t;
if (t != null)
foreach (Team r in l.FindAscendants(t))
{
yield return r;
}
}
Edit 2
In terms of the most efficient solution, a dictionary is the key.
As you can see now, there is no longer need to reverse the order.
So an optimized version would be
public static IEnumerable<Team> FindDescendandOptimized(this List<Team> l, Team from)
{
int count = l.Count;
var dic = l.ToDictionary(x => x.ParentTeam?.Name??"");
Team start = dic[from?.Name??""];
Team[] res = new Team[count];
res[count - 1] = start;
for (int i = count - 2; i >= 0; i--)
{
start = dic[start.Name];
res[i] = start;
}
return res;
}
with a test case and usage
List<Team> list = new List<Team>();
Team team = new Team();
team.Name = "0";
list.Add(team);
for (int i = 1; i < 200000; i++)
{
team = new Team();
team.Name = i.ToString();
team.ParentTeam = list.Last();
list.Add(team);
}
list.Reverse();
Console.WriteLine("Order List of " + list.Count +" teams");
Console.WriteLine("order is " + (TestOrder(list) ? "ok" : "ko"));
list.Shuffle();
Console.WriteLine("Shuffled List");
Console.WriteLine("order is " + (TestOrder(list) ? "ok" : "ko"));
DateTime start = DateTime.Now;
var res = list.FindDescendandOptimized(null);
list = res.ToList();
DateTime end = DateTime.Now;
Console.WriteLine("Reordered List");
Console.WriteLine("order is " + (TestOrder(list) ? "ok" : "ko"));
Console.WriteLine("Benchmark ms: " + (end - start).TotalMilliseconds);
Console.ReadLine();
where the test check is
static bool TestOrder(List<Team> list)
{
int tot = list.Count;
for (int i = 0; i < tot; i++)
{
if (!list[i].Name.Equals((tot-i-1).ToString()))
{
return false;
}
}
return true;
}
Edit 3
A final consideration, maybe obvious.
The absolutely most efficient way would have been to define a child team.
public class Team
{
public string Name;
public Team ParentTeam;
public Team ChildTeam;
}
appropriately filled like below
team.ParentTeam = list.Last();
list.Last().ChildTeam = team;
to enable an immediate reordering
DateTime start = DateTime.Now;
var res = list.OrderByChild(); //list.FindDescendandOptimized(null);
list = res.ToList();
DateTime end = DateTime.Now;
Console.WriteLine("Reordered List");
with a direct link
public static IEnumerable<Team> OrderByChild(this List<Team> l)
{
int count = l.Count;
Team start = l.First(x => x.ParentTeam == null);
Team[] res = new Team[count];
res[count - 1] = start;
for (int i = count - 2; i >= 0; i--)
{
start = start.ChildTeam;
res[i] = start;
}
return res;
}
I've struggled with this for quite some time. Today I finally wrote the following code.
The ViewModel contains an int property which later tells the view how many pages the data has been split into.
The controller splits the data by taking a specified amount of rows and, in the event of paging, splits by pageNumber * recordsPerPage
Take a look:
The ViewModel
public class ThreadPostsViewModel
{
public Thread Thread { get; set; }
public List<Post> Posts { get; set; }
public int Pages { get; set; }
}
The Controller
private int PostsPerPage = 10;
public ActionResult Thread(int id, int page = 1)
{
using (OrtundEntities Db = new OrtundEntities())
{
// get the thread and its parent data (parent for breadcrumbs)
var Thread = Db.Threads.Include(t => t.Title).FirstOrDefault(x => x.Id == id);
// create a list for the Posts
List<Post> Posts = new List<Post>();
// select based on paging
if (page == 1)
// no paging has happened, get the first set of records
Posts = Db.Posts.Include(x => x.User).Where(x => x.ThreadId == id).OrderByDescending(x => x.Date).Take(PostsPerPage).ToList();
else
// we're on a new page. Skip however many rows we've already seen
Posts = Db.Posts.Include(x => x.User).Where( x=> x.ThreadId == id).OrderByDescending(x => x.Date).Take(PostsPerPage).Skip(PostsPerPage * page).ToList();
// create and return the view model
ThreadPostsViewModel Model = new ThreadPostsViewModel
{
Thread = Thread,
Posts = Posts,
Pages = Posts.Count / PostsPerPage
};
return View(Model);
}
}
The View
#model Ortund.Models.ThreadPostsViewModel
<div class="paging">
#for (int i = 1; i < Model.Pages; i++)
{
string Url = String.Format("/View/Thread/{0}?page={1}", Model.Thread.Id, i);
#i
}
</div>
<div class="posts-list">
#foreach (var Post in Model.Posts)
{
<div class="post" id="#Post.Id">
</div>
}
</div>
In this code, assuming 300 posts are selected from the database and 10 posts are specified per page, then there should be 30 pages.
Even that's a hefty amount of links to fit into your page design so how can I minimize these paging links and display, say, 10 paging links only where, when you get to say, page 8, the links will change to show you 3-13, for example?
Even having the paging links display as follows would be preferable:
1 2 3 4 5 ... 90 91 92 93 94
In controller put value of current page:
ViewBag.currentPage = page;
In view you can do something like this (not tested):
<div class="paging">
#if (Model.Pages > 11 && ViewBag.currentPage > 6)
{
for (int i = ViewBag.currentPage - 6; i < ViewBag.currentPage -1; i++)
{
string Url = String.Format("/View/Thread/{0}?page={1}", Model.Thread.Id, i);
#i
}
for (int i = ViewBag.currentPage + 1; i < ViewBag.currentPage + 6; i++)
{
string Url = String.Format("/View/Thread/{0}?page={1}", Model.Thread.Id, i);
#i
}
}
else
{
for (int i = 1; i < Model.Pages; i++)
{
string Url = String.Format("/View/Thread/{0}?page={1}", Model.Thread.Id, i);
#i
}
}
</div>
I want to make a program using COM webbrowser which is a control in C#. In C#,I wrote these code:
myEles = webBrowser1.Document.All;
foreach (HtmlElement myEle in myEles)
{
if (myEle.TagName == myTag)
{
if (i == myIndex)
{
return myEle;
}
i++;
}
}
And I want to transfer it into QT. I've noticed that Qaxobject is essential. But I still got stuck when enum the element in myEles, my attempt code in QT:
int i = 0;
QAxObject* myEles = ui.MyWebView->querySubObject("Document");
myEles = myEles->querySubObject("All");
QAxObject* myEle;
int myCnt = myEles->dynamicCall("Count").toInt();
for (int j = 0;j < myCnt;j++)
{
myEle = myEles->querySubObject("[int]", j);
if(myEle->property("TagName") ==myTag)
{
if (i == myIndex)
{
myEle->dynamicCall("InvokeMember(const QString&)", "click");
return myEle;
}
i++;
}
}
With this, I can't even get the right myCnt . I just wonder how to write it correctly.
I've tried qt foreach,but still....
There is probably no "count" public slot you can call. Check the documentation with myEles->generateDocumentation(); for this.
To iterate through all your properties use the function propertyBag().
You will get a QMap with all properties:
QAxObject* myEles = ui.axWidget->querySubObject("Document");
myEles = myEles->querySubObject("All");
QMap<QString, QVariant> map = myEles->propertyBag();
int myCnt = map.size();
for (int j = 0;j < myCnt;j++)
{
...
}
I want to create a Property which can find the depth of the nested tree structure. The below static finds out the depth/level by recursion. But is it possible to make this function as a property in the same class instead of a static method?
public static int GetDepth(MenuGroup contextMenuItems)
{
if (contextMenuItems == null || contextMenuItems.Items.Count == 0)
return 0;
var subMenu = contextMenuItems.Items.Select(b => b as MenuGroup);
if (!subMenu.Any())
return 1;
var subLevel = subMenu.Cast<MenuGroup>().Select(GetDepth);
return !subLevel.Any() ? 1 : subLevel.Max() + 1;
}
Some more info on the code:
MenuGroup and MenuItem are derived from MenuBase
MenuGroup has children nodes with ObservableCollection<MenuBase> Items as Child Elements
MenuItem is a leave node without any child.
Well you could easily turn it into an instance property, yes:
public int Depth
{
get
{
if (Items.Count == 0)
return 0;
var subMenu = Items.Select(b => b as MenuGroup);
if (!subMenu.Any())
return 1;
var subLevel = subMenu.Cast<MenuGroup>().Select(x = > x.Depth);
return !subLevel.Any() ? 1 : subLevel.Max() + 1;
}
}
That won't quite work yet due to the handling of non-MenuGroup items, but it can easily be fixed, using OfType instead of the Select and then Cast:
public int Depth
{
get
{
// Completely empty menu (not even any straight items). 0 depth.
if (Items.Count == 0)
{
return 0;
}
// We've either got items (which would give us a depth of 1) or
// items and groups, so find the maximum depth of any subgroups,
// and add 1.
return Items.OfType<MenuGroup>()
.Select(x => x.Depth)
.DefaultIfEmpty() // 0 if we have no subgroups
.Max() + 1;
}
}
public string GenerateMenu()
{
StringBuilder sb = new StringBuilder();
sb.Append("<nav id=\"nvMenu\" class=\"main-nav\"><ul>");
sb.Append(PrepareMenuUL(AppConfig._AppConfigInstance.Navigation.FirstOrDefault().NavigationClass));
sb.Append("</ul></nav>");
return sb.ToString();
}
private string PrepareMenuUL(List<Navigation> navigation)
{
StringBuilder sb = new StringBuilder();
if (Liflag == 1)
{
sb.Append("</li>");
Liflag = 0;
}
foreach (var item in navigation)
{
var subMenu = item.NavigationClass.Select(b => b as Navigation);
if (subMenu.Any())
{
sb.Append("<li class=\"dropdown\">");
if (subMenu.Any() && item.Url == "#")
sb.Append(string.Format("{1}<i class=\"icon-arrow\"></i>", BaseUrl + item.Url, item.Name));
else if (subMenu.Any() && item.Url != "#" && item.Url != null)
sb.Append(string.Format("{1}<i class=\"icon-rightarrow\"></i>", BaseUrl + item.Url, item.Name));
}
else
{
sb.Append("<li>");
sb.Append(string.Format("{1}", BaseUrl + item.Url, item.Name));
}
if (subMenu.Any())
sb.Append("<ul class=\"wd190\">");
if (item.NavigationClass.Count > 0)
{
Liflag = 1;
sb.Append(PrepareMenuUL(item.NavigationClass));
}
sb.Append("</li>");
if (subMenu.Any())
sb.Append("</ul>");
}
return sb.ToString();
}
I'm encountering an unfamiliar problem with functionality. I think it has something to do with scope of a loop, and server-side code operations/manipulation when rendering a page.
Say I want to repeat a Table Row - each hosts a text input, rows and their textboxes are rendered with values according to content of DATABASE "binded" Data.
Everything works perfectly until more requirements are added - READONLY Attribute And event Key (javascript small validation task).
Otherwise it does work, alternating rows via two separated strings that I "inject" with string format on a condition of if row count is odd vs even, then I tried to filter some of columns to have a keypress event bound to a js function and another attribute as a string.
If the string is empty, then end part of the element "declaration" will be empty
if condition was met, then that string is assigned with value "ReadOnly" and js string is assigned with keypress event "calling a function code".
Here's the code. The situation is weird as style attributes, information of current column, columns names, everything does function as expected but those two READONLY Attribute And event Key (javascript small validation task) that do not.
Render a dynamic Table Code
This is the front code, c# code behind is used mostly (to keep a little code client-side as possible)
`ControlsInteraction.WithTable.Design()`
AND
`ControlsInteraction.WithTable.ExtractData()`
are dealing with dynamic functions of rendering and translation of columns names and values
int count = 0;
bool TblOk = DebugTests.Sesseion.SeSn.Raised(DebugTests.Flag.HT_DB_CPA_Table_init_Complete);
if (TblOk)
{
string TextBxRendr = "";//holds Renderd <TD> base String-code
string AltrnatBgColor;
string NoAttribute = "";
string Js_NumericKprss = "onkeypress=\"return onlN(event)\""
string ReadOnly = "READONLY";
var TimesCol = ALLTablesDataSet.Tables[Tbl1.TableName].Columns;
string DtrawTbl1 = Tbl1.TableName;
ControlsInteraction.WithTable.Design Tbldz =
new ControlsInteraction.WithTable.Design();
ControlsInteraction.WithTable.ExtractData DtExtrct =
new ControlsInteraction.WithTable.ExtractData();
foreach (System.Data.DataRow TimesRow in ALLTablesSet.Tables[DtrawTbl].Rows)
{
AltrnatBgColor= Tbldz.RowsBGColorAlternate(RDE.DataRowToInt(TimesRow, "RecordNum"),true);
altBgColOnly = Tbldz.RowsBGColorAlternate(RDE.DataRowToInt(TimesRow, "RecordNum"), false);
Response.Write(string.Format("<tr {0}>",AltrnatBgColor));
for (int i = 0; i < TimesRow.ItemArray.Length; i++)
{
if (i != (TimesRow.ItemArray.Length - 1))
{
Js_NumericKprss = "onkeypress=\"return onlN(event)\"";
//asking for: current row will Not be read only via its name
if (DtExtrct.CurrRowIs(TimesRow, MyDBSchema.DBs_Cols.TblCPAReport.Comments, DtExtrct.DataRowToInt(TimesRow, "RecordNum")))
Js_NumericKprss = NoAttribute; // same goes with the other manipulation i've needed to implement on each column
TextBxRendr = string.Format(
"<td><input type='text' id=\"{0}_{1}\" value=\"{2} \" style=\"width:50px;{3} border:none; \" class=\"RepTblDataTDs\" {4} {5} \\></td>",
TimesCol[i], TimesRow["RecordNum"], TimesRow[i], AltrnatBgColor,Js_NumericKprss,ReadOnly
);
}
else
{
TextBxRendr = string.Format(
"<td><input type='image' id=\"{0}_{1}\" src=\"images/Save.png\" style=\"width:25px;{2}\" style=\"width:25px\" onclick=\"UbpdateTblCPA(this, {1});\" /></td>",
"img",i + 1, AltrnatBgColor
);
}
Response.Write(TextBxRendr);
count++;
}
}
}
Is injected properly and the read only part READONLY Attribute, and event Key - (javascript small validation task)
Either functions on all or none
What am I doing wrong?
answering my own Question aventually answer is
...well everything , including #Patrics Comment Was Wrong
i can just say put good attention to : how to work with DataTable DataRow, DataTable DataColumns
and the relations for and foreach variables scope
use your visual sudio debugger on every line to check on your codes values
i did not have the time to rename variables but if you need to make a dynamic
html table out of a DB table this is the way
foreach (System.Data.DataRow TimesRow in ALLTablesSet.Tables[DrawTbl].Rows)
{
recordNum = RDE.DataRowToInt(TimesRow, "RecordNum");
AltBgCol = Tbldz.RowsBGColorAlternate(RDE.DataRowToInt(TimesRow, "RecordNum"), true);
altBgColOnly = Tbldz.RowsBGColorAlternate(RDE.DataRowToInt(TimesRow, "RecordNum"), false);
Response.Write(string.Format("<tr {0}>", AltBgCol));
for (int i = 0; i < TimesRow.ItemArray.Length; i++)
{
if (i != (TimesRow.ItemArray.Length - 1))
{
Js_NumericKprss = "onkeypress=\"return onlN(event)\""; ReadOnly = "";
if (RDE.CurrRowIs(TimesRow, HentalDBSchema.HTDB_Cols.TblTimeCPAReport.Comments, i))
{
Js_NumericKprss = ""; ReadOnly = "";
}
else if (RDE.CurrRowIs(TimesRow, HentalDBSchema.HTDB_Cols.TblTimeCPAReport.Fines, i)
|| RDE.CurrRowIs(TimesRow, MyDBSchema.DBs_Cols.TblCPAReport.PhoneExpences, i)
|| RDE.CurrRowIs(TimesRow, MyDBSchema.DBs_Cols.TblCPAReport.SalaryPerDay, i)
|| RDE.CurrRowIs(TimesRow, MyDBSchema.DBs_Cols.TblCPAReport.SalaryPerMonth, i)
|| RDE.CurrRowIs(TimesRow, MyDBSchema.DBs_Cols.TblCPAReport.TotalGrossWages, i)
|| RDE.CurrRowIs(TimesRow, MyDBSchema.DBs_Cols.TblCPAReport.TravelFee, i))
{
ReadOnly = "";
Js_NumericKprss = "onkeypress=\"return onlN(event)\"";
}
else
ReadOnly = "READONLY";
TxtRndr = string.Format("<td><input type='text' id=\"{0}_{1}\" value=\"{2} \" style=\"width:50px;{3} border:none; \" class=\"RepTblDataTDs\" {5} {6} \\></td>{4}", TimesCol[i], TimesRow["RecordNum"], TimesRow[i], altBgColOnly, Environment.NewLine + "\t\t\t", Js_NumericKprss, ReadOnly);
}
else
{
TxtRndr = string.Format("<td><input type='image' id=\"{0}_{1}\" src=\"images/Save.png\" style=\"width:25px;{3}\" style=\"width:25px\" onclick=\"UbpdateTblCPA(this, {1});\" /></td>{4}", "imgBut", i + 1, TimesRow[i], altBgColOnly, Environment.NewLine + "\t\t\t");
}
Response.Write(TxtRndr);
count++;
}
}
i am adding all researches i have made to be more easy on the data extraction and some more methods i have worked on so if u like to use it feel free to ...
public class ControlsInteraction
{
public class WithDDL
{
public class GetSelVal
{
public string AsString(DropDownList DDLToCollectValusFrom)
{
return DDLToCollectValusFrom.SelectedValue;
}
public int AsInt(DropDownList DDLToCollectValusFrom)
{
if(DDLToCollectValusFrom.SelectedValue != null)
return Convert.ToInt32(DDLToCollectValusFrom.SelectedValue);
return 666;
}
}
public List<string> GetListItems_Values(DropDownList DDLToCollectValusFrom)
{
List<string> LST_DDLValues = new List<string>();
foreach (ListItem item in DDLToCollectValusFrom.Items)
{
LST_DDLValues.Add(item.Value);
}
return LST_DDLValues;
}
public List<string> GetListItems_Text(DropDownList DDLToCollectTextFrom)
{
List<string> LST_DDLTEXT = new List<string>();
foreach (ListItem item in DDLToCollectTextFrom.Items)
{
LST_DDLTEXT.Add(item.Text);
}
return LST_DDLTEXT;
}
}
public static class WithPlcHldr
{
public static void AddCtrl(PlaceHolder PlcHldrID, Control CntrID)
{
PlcHldrID.Controls.Add(CntrID);
}
}
public class WithTable
{
public class Design
{
public string RowsBGColorAlternate(int RowCounter, bool AddWithStyleAsStandAlone = false)
{
string BgCol = ""; bool bgclaltrnator;
if (RowCounter > 0)
{
RowCounter++;
bgclaltrnator = (RowCounter % 2) == 0;
if (bgclaltrnator)
BgCol = "#70878F";
else BgCol = "#E6E6B8";
}
if (AddWithStyleAsStandAlone)
return string.Format("style=\"background-color:{0};\"", BgCol);
return string.Format("background-color:{0};", BgCol);
}
}
public class ExtractData
{
public string ColumnValueFromCurrRow(DataRow DtRow, string RequestedColName)
{
return "";
}
public string DataRows_ColumnToString(DataRow Data_RowToActOn, string keyColName)
{
var tmp = Data_RowToActOn[keyColName];
return Data_RowToActOn[keyColName].ToString();
}
public int DataRowToInt(DataRow Data_RowToActOn, string keyColName)
{
string tmp = Data_RowToActOn[keyColName].ToString();
return Convert.ToInt32(tmp);
}
public bool CurrColumnIs(DataColumn Data_RowToQuestion, string ColumnName)
{
string tmp = Data_RowToQuestion.ToString();
return tmp == ColumnName;
}
public bool CurrRowIs(DataRow Data_RowToQuestion, string RowName, int CurrIndex)
{
string ColsName = Data_RowToQuestion.Table.Columns[CurrIndex].ToString();
return ColsName == RowName;
//this is curent value - by index
//string currentColumn = Data_RowToQuestion.ItemArray[CurrIndex].ToString();
}
}
}
}