int numberOfListItems = CheckBoxList1.Items.Cast<ListItem>().Count(li => li.Selected);
Loop through Visual Studio checkbox list c#
Its a bit easier using Javascript, but here is how to use c# and loop through the variables in a checkbox list control from Visual Studio.
You have a Checkbox List control on your page: CheckBoxList1. You loop through the list of items and use the data…
In your codebehind, you are in a function to gather the data from objects:
myFunction(){... // doing stuff // need to get the data from the check box list checked items string selectedItems = ""; for(int i = 0; i < CheckBoxList1.Items.Count; i++) { if (CheckBoxList1.Items[i].Selected) { selectedItems += CheckBoxList1.Items[i].Value + ", "; } } ...}
If the checkbox list had selected values of SUN, WED and FRI then the string selectedItems would contain the text : “SUN, WED, FRI, ”
I would use a trim to remove the trailing comma.
Here is another method that casts the Checkbox items as a list and uses for each to loop through.
string FoundScholAppSport = ""; foreach (ListItem val in CheckBoxListSports.Items) { if (val.Selected) { FoundScholAppSport += val.Value + " "; } }
Create Data Table C# datatable
Sometimes need to hand craft a data table for use.
DataTable dt = new DataTable(); DataRow dr; dt.Columns.Add(new System.Data.DataColumn("EventTitle", typeof(String))); dt.Columns.Add(new System.Data.DataColumn("EventID", typeof(String))); dr = dt.NewRow(); dr[0] = "Emergency Alert"; dr[1] = "Event Id"; dt.Rows.Add(dr);
Here is how you could use that in a function to return the datatable:
private DataTable GetDummyData() { DataTable dt = new DataTable(); DataRow dr; dt.Columns.Add(new System.Data.DataColumn("EventTitle", typeof(String))); dt.Columns.Add(new System.Data.DataColumn("EventID", typeof(String))); dt.Columns.Add(new System.Data.DataColumn("Start_Time", typeof(String))); dt.Columns.Add(new System.Data.DataColumn("End_Time", typeof(String))); dt.Columns.Add(new System.Data.DataColumn("EventDetails", typeof(String))); dr = dt.NewRow(); dr[0] = "Christmas Party"; dr[1] = "1"; dr[2] = "12/23/2017 12:00:00"; dr[3] = "12/23/2017 14:00:00"; dr[4] = "Please drop by our Christmas party and bring gifts!"; dt.Rows.Add(dr); return dt; }
Custom command button in ASP gridview C#
A powerful feature to add your own button to the gridview and have custom commands. Most basic is you would want to pass the id of the record so you can do stuff to it.
In your gridview add a templatefield with a button as so…
<asp:TemplateField HeaderText="Actions"> <ItemTemplate> <asp:Button runat="server" CssClass="btn btn-sm btn-danger" Text="Do Something" CommandName="CustomFunction" CommandArgument='<%# Eval("Id") %>' /> </ItemTemplate> </asp:TemplateField>
Then you use the RowCommand event of the gridview to do what you need to…
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "CustomFunction") { string recordId = e.CommandArgument.ToString(); // do what ever you need to do with the record id } }
Validate a textbox entry c# using tryParse
In strongly typed language, there is no room for error when a user enters data that is expected to be put into a data storage system.
For example, I need to covert an input from textbox1 that is supposed to be a number to be used in a total:
int fundAmt = Convert.ToInt32(TextBoxPersonalFundAmt.Text);
If the user enters unexpected non numeric characters, this conversion will fail and make your app error out. Instead of directly trying to convert, we can cast a Boolean on our input data using TryParse to parse the number into an integer…
bool isNumeric = int.TryParse(TextBoxPersonalFundAmt.Text, out n);
Now we can validate the input and perform the necessary calculations with the numbers.
int fundAmt; bool isNumeric = int.TryParse(TextBoxPersonalFundAmt.Text, out fundAmt); if (!isNumeric) { errInfo += "Error: Its not a valid number in the amount box "; lblLogErr.Text = errInfo; pageValid = false; } else { // calculate the total }
Another good example is the date field. A user is expected to enter a valid date for their birthday. There are many ways that a user would normally express that date. We of course use a client side validation to ensure that the format is entered correctly, but we need to have a server side validation of that data as well.
DateTime SponsorSigDate; if(!DateTime.TryParse(TextBoxSponsorDate1.Text, out SponsorSigDate)) { pageValid = false; errInfo += "Error: Enter a valid date. "; }
Add controls to page dynamic c#
Here is a good way to add controls to the page
protected void TextBoxDependentNum_TextChanged(object sender, EventArgs e)
{
if (Convert.ToInt32(TextBoxDependentNum.Text) > 0)
{
for (int i = 0; i < Convert.ToInt32(TextBoxDependentNum.Text); i++)
{
PanelDependentInfo.Controls.Add(new LiteralControl(“<br />”));
TextBox MyTextBox = new TextBox();
Label MyLabel = new Label();
MyLabel.Text = “Dependent Name: “;
MyLabel.ID = “LabelDependentName” + i.ToString();
MyLabel.CssClass = “supercheckboxlabel”;
MyTextBox.ID = “TextBoxDependentName” + i.ToString();
PanelDependentInfo.Controls.Add(MyLabel);
PanelDependentInfo.Controls.Add(MyTextBox);
TextBox MyTextBox2 = new TextBox();
Label MyLabel2 = new Label();
MyLabel2.Text = “Dependent Birthdate: “;
MyLabel2.CssClass = “supercheckboxlabel”;
MyLabel2.ID = “LabelDependentBirthdate” + i.ToString();
MyTextBox2.ID = “TextBoxDependentBirthdate” + i.ToString();
PanelDependentInfo.Controls.Add(MyLabel2);
PanelDependentInfo.Controls.Add(MyTextBox2);
PanelDependentInfo.Controls.Add(new LiteralControl(“<br />”));
}
}
}
Vulnerability Scanners
OpenVAS is a framework of several services and tools offering a comprehensive and powerful vulnerability scanning and vulnerability management solution. The framework is part of Greenbone Networks‘ commercial vulnerability management solution from which developments are contributed to the Open Source community since 2009.
Firesheep is an extension for the Firefox web browser that uses a packet sniffer to intercept unencrypted session cookies from websites such as Facebook and Twitter. The plugin eavesdrops on Wi-Fi communications, listening for session cookies. When it detects a session cookie, the tool uses this cookie to obtain the identity belonging to that session. The collected identities (victims) are displayed in a side bar in Firefox. By clicking on a victim’s name, the victim’s session is taken over by the attacker.[
SQL Map Automatic SQL injection and database takeover tool
http://sqlmap.org/
sqlmap is an open source penetration testing tool that automates the process of detecting and exploiting SQL injection flaws and taking over of database servers. It comes with a powerful detection engine, many niche features for the ultimate penetration tester and a broad range of switches lasting from database fingerprinting, over data fetching from the database, to accessing the underlying file system and executing commands on the operating system via out-of-band connections.
Cisco Umbrella Investigate
Investigate provides the most complete view of the relationships and evolution of domains, IPs, autonomous systems (ASNs), and file hashes. Accessible via web console and API, Investigate’s rich threat intelligence adds the security context needed to uncover and predict threats.
https://umbrella.cisco.com/products/threat-intelligence
****xerosploit
xxsstrike
Robotics Development Using Ubuntu
https://insights.ubuntu.com/2017/07/12/robot-development-made-easy-with-husarion-core2-ros-running-ubuntu/
https://insights.ubuntu.com/webinar/webinar-building-a-commercial-robot-with-open-source/
Web Assembly compiler
There are some exciting new developments in the world of browser based programming. WebAssembly or wasm is a new portable, size- and load-time-efficient format suitable for compilation to the web. WebAssembly is currently being designed as an open standard by a W3C Community Group that includes representatives from all major browsers.
I’m really excited to test this out. Unreal Engine 4 now supports the new WebAssembly standard (also known as WASM) for HTML5, the fastest and most efficient way to compile and run C++ for the web! They are using Mozilla’s latest Emscripten toolchain (v1.37.9).
Vectr – Free Vector Graphics Software
Vectr is a free graphics software used to create vector graphics easily and intuitively. It’s a simple yet powerful web and desktop cross-platform tool to bring your designs into reality.
The coolest feature is the real time sharing. Send anyone a Vectr document for real-time collaboration without the wait. Others can watch you create and edit designs live, whether you’re in the web app or desktop version.