Only top row of DataGridView updating? - c#

I have a DataGridView that I'm populating from a list. The function that edits this list is called LoadCollectionData()'. Extra rows get added to the list just fine, and the relevant data pertaining to that row populates when the row is added.
The problem is that later on when other data is being changed that'd alter what's displayed on the datagrid, only the top row continues to update, all of the others remain the same.
Here's the code for the method:
public bool haschanged = false;
public class KeywordDensity
{
public bool included { get; set; }
public string keyword { get; set; }
public string occurences { get; set; }
public string density { get; set; }
}
public int WordCount(string txtToCount)
{
string pattern = "\\w+";
Regex regex = new Regex(pattern);
int CountedWords = regex.Matches(txtToCount).Count;
return CountedWords;
}
public int KeywordCount(string txtToCount, string pattern)
{
Regex regex = new Regex(pattern);
int CountedWords = regex.Matches(txtToCount).Count;
return CountedWords;
}
public List<KeywordDensity> LoadCollectionData()
{
string thearticle = txtArticle.Text.ToLower();
string keywordslower = txtKeywords.Text.ToLower();
string[] keywordsarray = keywordslower.Split('\r');
List<KeywordDensity> lsikeywords = new List<KeywordDensity>();
bool isincluded = false;
double keywordcount = 0;
double wordcount = WordCount(thearticle);
double thedensity = 0;
foreach (string s in keywordsarray)
{
if (s != "")
{
keywordcount = KeywordCount(thearticle, s);
thedensity = keywordcount / wordcount;
thedensity = Math.Round(thedensity, 4) * 100;
if (thearticle.Contains(s))
{
isincluded = true;
}
else
{
isincluded = false;
}
lsikeywords.Add(new KeywordDensity()
{
included = isincluded,
keyword = s,
occurences = keywordcount.ToString(),
density = thedensity.ToString() + "%"
});
}
}
return lsikeywords;
}
private void txtArticle_TextChanged(object sender, EventArgs e)
{
if (haschanged == false)
haschanged = true;
lblWordCountNum.Text = WordCount(txtArticle.Text).ToString();
dataGrid.DataSource = LoadCollectionData();
}
private void dataGrid_MouseUp(object sender, MouseEventArgs e)
{
int cursorpos = 0;
string copied = "";
if (dataGrid.CurrentCellAddress.X == 1) //Only grab content if the "Keyword" column has been clicked on
copied = " " + dataGrid.CurrentCell.Value.ToString() + " ";
cursorpos = txtArticle.SelectionStart;
txtArticle.Text = txtArticle.Text.Insert(cursorpos, copied);
}
What's even more odd, is that when I click on any of the rows, then they immediately update. However, unless the row is clicked on (unless it's the top one) it doesn't update.
Because of this, I suspect there may be some property I need to set on the dataGrid itself, or I need to somehow tell each row to refresh through code.
What's the dealio?
EDIT: It appears that the only reason that the cell that's clicked on updates is because I actively grab content from the cell. I commented out the code below and it stopped updating even when clicked on. It then would only update the top row's values and that's it.
Code:
//Moved above in EDIT 3
EDIT 2: Here's the class declaration for KeywordDensity:
//Moved above in EDIT 3
EDIT 3: Posted whole schebang.

I modified the code slightly, try this code.
string[] keywordsarray = keywordslower.Split
(new char[] {'\r','\n' }, StringSplitOptions.RemoveEmptyEntries);

You may need to Invalidate() the control to trigger a repaint.

call the DataBind() method of the datagrid. That should do.
Update
There's a ResetBindings() in that case.

Related

How to join same lines in textbox and count them

Hey Guys I have Problem I have a textbox who will have sometimes same lines now I need to count them and show the number in joined line with the text
private void textBox1_TextChanged(object sender, EventArgs e)
{
string[] same =textBox1.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None).Distinct().ToArray();
textBox1.Text = string.Join("\r\n", same);
}
in this code it will join the lines and I am able to see just one line but I need a count of lines and if I have some number in that line to count that also
for example:
Earth 2
Water
Air
Earth
Expected :
Earth x2 4
Water
Air
Your question is a bit confusing, BTW I solve it this way.
First I made a class for each result item
Result Class
public class Result
{
public string Item{ get; set; }
public int Count{ get; set; }
public int Value{ get; set; }
}
Then I have a button to translate the 'user input' to the desired format
You can run this method as textbox1_changed
Button Translate Clicked Method
private void btnTranslate_Click(object sender, EventArgs e)
{
var items = textBox1.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None).ToList();
var results = new List<Result>();
foreach (var item in items)
{
var text = item;
var value = 0;
var row = item.Split(' ').ToList();
if (row.Count == 2) // item contains value like: Earth 2
{
text = row[0];
Int32.TryParse(row[1], out value);
}
var result = results.FirstOrDefault(r => r.Item.Equals(text));
if (result == null) // first time item apears in the list
{
result = new Result
{
Item = text,
Count = 1,
Value = value
};
results.Add(result);
}
else // item added before should increase the count
{
result.Count++;
result.Value += value;
}
}
textBox2.Text = Prettify(results); // lets make the result pretty
}
In the end I declared Prettify function to make the result as you wanted
Prettify Method
public string Prettify(List<Result> results)
{
var prettify = "";
int row = 0;
foreach (var result in results)
{
prettify += $"{++row}. {result.Item}"; // 1. Earth
if (result.Count > 1)
prettify += $" x{result.Count}"; // 1. Earth x2
if (result.Value > 0)
prettify += $" {result.Value}"; // 1. Earth x2 4
prettify += Environment.NewLine;
}
return prettify;
}
Here is the output
Output
I guess the core is right, you could customize it
Have fun

C# Multiplying the values of an array together which are loaded from a textfile into a List<>

So I have an array, strArray, that stores the values of my text files which has 3 columns. I think this is called a two or three dimensional array, not sure. Or maybe one dimensional. I have a List<> called Inventory which adds the data to it.
I currently have three successful columns I just need the fourth. The fourth column is the second and third column multiplied together, which is a total price. The second column is an int, "Number of Items", the third is a decimal, "Price" and the fourth is a decimal, "Total Price" which is Number of Items * Price.
I'll go ahead and post my code, I am also using four list boxes for the data. Three columns (or three list boxes) work fine, but I just gotta get the fourth one figured out.
Sorry for the large amount of code, I figured if I copied all of it it'll make it easier to see if an error occurred earlier on. btnLoadInfo_Click is the event/method where the main issue is.
namespace TCSCapstone
{
public partial class frmInventory : Form
{
List<frmInventory> Inventory = new List<frmInventory>();
public frmInventory()
{
InitializeComponent();
}
public string ItemName { get; set; }
public int NumberOfItems { get; set; }
public decimal Price { get; set; }
public decimal TotalPrice { get; set; }
string selectedList = "";
private void cmbList_SelectedIndexChanged(object sender, EventArgs e)
{
selectedList = this.cmbList.GetItemText(this.cmbList.SelectedItem);
lstItemName.DataSource = null;
lstNumberOfItems.DataSource = null;
lstPrice.DataSource = null;
lstItemName.Items.Clear();
lstNumberOfItems.Items.Clear();
lstPrice.Items.Clear();
lstTotalPrices.Items.Clear();
if (selectedList == "Creative Construction")//if the selected combo box item equals the exact string selected
{
selectedList = "creative"; //then the string equals creative, which is creative.txt but I add the .txt in the btnLoadInfo method
} else if (selectedList == "Paradise Building")
{
selectedList = "paradise";//this is for paradise.txt
}
else if (selectedList == "Sitler Construction")
{
selectedList = "sitler";//this is for sitler.txt
}
else
{
MessageBox.Show("Please select one of the items.");
}
}`
private void btnLoadInfo_Click(object sender, EventArgs e)
{
Inventory.Clear(); //Clears the entire Inventory List
using (StreamReader invReader = new StreamReader(selectedList +
".txt"))
{
while (invReader.Peek() >= 0)
{
string str;
string[] strArray;
str = invReader.ReadLine();
strArray = str.Split(',');
frmInventory currentItem = new frmInventory();
currentItem.ItemName = strArray[0];
currentItem.NumberOfItems = int.Parse(strArray[1]);
currentItem.Price =
decimal.Parse(strArray[2]);
strArray[1].
currentItem.TotalPrice = decimal.Parse(strArray[1] *
strArray[2]);
Inventory.Add(currentItem);
}
}
displayLists(); //Calls the displayLists method to update list
//boxes at the end of the button click event
}//end of btnLoadInfo
void displayLists()
{
//Resets the listboxes datasources by setting them to null
lstItemName.DataSource = null;
lstNumberOfItems.DataSource = null;
lstPrice.DataSource = null;
lstItemName.Items.Clear();
lstNumberOfItems.Items.Clear();
lstPrice.Items.Clear();
lstTotalPrices.Items.Clear();
lstItemName.DisplayMember = "ItemName";
lstItemName.ValueMember = "";
lstItemName.DataSource = Inventory;
lstNumberOfItems.DisplayMember = "NumberOfItems";
lstNumberOfItems.ValueMember = "";
lstNumberOfItems.DataSource = Inventory;
lstPrice.DisplayMember = "Price";
lstPrice.ValueMember = "";
lstPrice.DataSource = Inventory;
}
Your TotalPrice property should be a mathematical equation, not something you set independently of the number of items and their prices.
Change the property to this:
public decimal TotalPrice{
get{ return NumberOfItems * Price; }
}
Delete the line that sets TotalPrice in your loop; it's no longer necessary because you've set the item price and the number of items; the total price inherently follows from these
You're trying to multiply two strings together. Instead, multiply the numeric values that you have already parsed:
currentItem.TotalPrice = currentItem.NumberOfItems * currentItem.Price;

Creating a function to be reusable multiple times in my code

I want to be able to call the following function multiple times through out my code to fill different groups of 8 text boxes in my form.
Right now reference is being passed in "tbPlay" from where it is being called initially in the code.
Each time this function will be called it will be to fill different text box groups.
I am trying to think of a way of using the empty for loop to create the necessary variable names to replace tbPlay0-7 in my case statement, so it isn't only usable for one group of text boxes in my code. I am not sure it can be done.
Can anyone help.
private void convertBasetoDrawn(string numBase, string reference)
{
string baseNumber = numBase;
for (int i = 0; i < 8; i++)
{
//some code here to create variables to replace the text box names in the
//following case statement
}
switch (baseNumber)
{
case "000":
tbPlay0.Text = "000";
tbPlay0.ForeColor = Color.Red;
tbPlay1.Text = "500";
tbPlay2.Text = "050";
tbPlay3.Text = "005";
tbPlay4.Text = "550";
tbPlay5.Text = "505";
tbPlay6.Text = "055";
tbPlay7.Text = "555";
tbPlay7.ForeColor = Color.Red;
break;
}
}
Create a List<TextBox> for each group:
List<TextBox> list01 = new List<TextBox>() { tbPlay0, tbPlay1, ....};
List<TextBox> list02 = new List<TextBox>() { ..., ... , ....};
// ..
}
And pass such a group to the function:
private void convertBasetoDrawn(List<TextBox> list, string numBase, string reference)
{
string[] texts = new string[8]
{ "000", "500", "050", "005", "550", "505", "055", "555" };
for (int t = 0; t < list.Count; t++) list[t].Text = texts[t];
list[0].ForeColor = Color.Red;
list[7].ForeColor = Color.Red;
}
Assuming the texts will always look like that. If they depend on, maybe numbase you can construct them dynamically as well, as long as you know the rules.. Maybe even a simple replacement will do the job?
You didn't use reference, btw..
Now, I'm just guessig here, but maybe this is the pattern for your texts..:
string[] texts = new string[8]
{ "nnn", "dnn", "ndn", "nnd", "ddn", "dnd", "ndd", "ddd" };
for (int s = 0; s < texts.Length; s++)
texts[s] = texts[s].Replace("d", numBase).Replace("n", reference);
Now you can call it like this:
convertBasetoDrawn(list01, "0","5");
Update: For the rules as I understand them now you could do:
string newText = "";
for (int s = 0; s < texts.Length; s++)
{
newText = "";
for (int i = 0; i < 3; i++)
{
if (texts[s][i] == 'n') newText += numBase[i];
else newText += (Convert.ToByte(numBase[i].ToString()) +
Convert.ToByte(reference[0].ToString()) ).ToString("0");
}
texts[s] = newText;
}
and call it like this:
convertBasetoDrawn(list01, "001", "5");
or
convertBasetoDrawn(list02, "000", "1");
Note: no carry over here.. You'd have to define rules for that and code it yourself..
It's not clear how you plan to identify the specific group of eight. But let's assume you have somehow.
Then, if I were writing this code, I would use a UserControl to encapsulate the repeated pattern, exposing the eight TextBox controls — or rather, the properties of them that you want access to — as properties. E.g.
class TextBoxGroup : UserControl
{
public string Text1
{
get { return textBox1.Text; }
set { textBox1.Text = value; }
}
public Color ForeColor1
{
get { return textBox1.ForeColor; }
set { textBox1.ForeColor = value; }
}
public string Text2
{
get { return textBox2.Text; }
set { textBox2.Text = value; }
}
public Color ForeColor2
{
get { return textBox2.ForeColor; }
set { textBox2.ForeColor = value; }
}
// ...
public string Text8
{
get { return textBox8.Text; }
set { textBox8.Text = value; }
}
public Color ForeColor8
{
get { return textBox8.ForeColor; }
set { textBox8.ForeColor = value; }
}
}
Then in your method, rather than whatever logic you planned on using to figure the starting index for your group, instead you just retrieve the appropriate TextBoxGroup instance and use it in the switch, like this:
case "000":
textBoxGroup.Text1 = "000";
textBoxGroup.ForeColor1 = Color.Red;
textBoxGroup.Text2 = "500";
textBoxGroup.Text3 = "050";
textBoxGroup.Text4 = "005";
textBoxGroup.Text5 = "550";
textBoxGroup.Text6 = "505";
textBoxGroup.Text7 = "055";
textBoxGroup.Text8 = "555";
textBoxGroup.ForeColor8 = Color.Red;
break;
A variation on the above would encapsulate the properties with setter methods taking an index. E.g.
class TextBoxGroup : UserControl
{
// Initialized in constructor to be the eight TextBoxes
private TextBox[] _textboxes;
public void SetText(int i, string text)
{
_textboxes[i].Text = text;
}
}
Of course, if you don't want to use a UserControl, you could just initialize a similar data structure in the main form instead, so that the controls can be accessed by index. But personally, I'd prefer the UserControl as it makes it easier to reuse and ensure consistency across all the groups of TextBox controls.

select combobox item by value C#

I have a combobox , bound to Datatable
and have the following properties:
cboCars.DisplayMember = "carLiscen";
cboCars.ValueMember = "carNo";
How can I select the DisplayMember when I know the ValueMember ?
If you have a ValueMember set you can select using SelectedValue
cboCars.DisplayMember = "carLiscen";
cboCars.ValueMember = "carNo";
cboCars.SelectedValue = "valuemember value";
You can use cboCars.SelectedValue = "123"; property for this. Here's a code snippet which will show it in action.
public void Test()
{
ArrayList info = new ArrayList();
info.Add(new CarInfo { CarLiscen = 123456, CarNo = 123});
info.Add(new CarInfo { CarLiscen = 234567, CarNo = 234 });
cboCars.DataSource = info;
cboCars.DisplayMember = "CarLiscen";
cboCars.ValueMember = "CarNo";
cboCars.SelectedValueChanged +=
delegate(object sender, EventArgs e)
{
if (cboCars.SelectedIndex != -1)
{
this.Text = cboCars.SelectedValue.ToString();
}
};
cboCars.SelectedValue = 234;
}
And if you wonder what is the definition of CarInfo. Here's its code (which is fairly simple):
public class CarInfo
{
public int CarLiscen { get; set; }
public int CarNo { get; set; }
}
Hope this helps.
You can search for the correct item and set it to that, very simple:
cbTEST.SelectedIndex = cbTEST.FindStringExact("your search string here");
or select an item based on an ListViewItem:
cbTEST.SelectedIndex = cbTEST.FindStringExact(lvTEST.SelectedItems[0].SubItems[0].Text);
thats it. very simple!
Hi Guys the best way if searching for a text or value
is
int Selected;
int count = ComboBox1.Items.Count;
for (int i = 0; (i<= (count - 1)); i++)
{
ComboBox1.SelectedIndex = i;
if ((string)(ComboBox1.SelectedValue) == "SearchValue")
{
Selected = i;
}
}
ComboBox1.SelectedIndex = Selected;
The problem is that the combobox expect the exact type.
So if you for example use a datagridview and you see the value (int) in the field, you pass it to the SelectedValue property of the combo. But in fact you are not passing an integer, you are passing an object. That is what usually is going wrong. It my a while to sort this out, but finally I have found how to do it...
How to solve this... easy:
For example, you have an ID (integer in the database), then you need to do something like this:
This is the one that I did and it does not work:
cmbFilter.SelectedValue = dgvListOfFilters.Rows[intRowSelected].Cells[3].Value;
You should do this to make it work:
int intCategory = Convert.ToInt32(dgvListOfFilters.Rows[intRowSelected].Cells[3].Value);
cmbFilter.SelectedValue = intCategory;
Hope this will be helpfull for many people...

Unexpected behaviour of dynamic html rendering a table with data via C#

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();
}
}
}
}

Categories

Resources