Passing a function as a parameter in injecting data into SQL Server - c#

I wrote a GetLoan function:
private void GetLoan(RadioButton radiobutton)
{
if(radiobutton.Checked)
{
MessageBox.Show(radiobutton.Text);
}
}
and in order to get the necessary data from the radio button I did this,
bookCom = new SqlCommand("UPDATE d_Book SET ISBN = #isbn, Author = #author, Title = #title, Publisher = #publisher, Date = #date, Loan = #loan WHERE ISBN = #isbn ", bookCon);
String ISBN = textISBN.Text;
String Author = textAuthor.Text;
String Title = textTitle.Text;
String Publisher = textPublisher.Text;
String Date = textDate.Text;
GetLoan(rdbtn_Yes); // worked fine
GetLoan(rdbtn_No); // worked fine
bookCom.Connection = bookCon;
bookCon.Open();
if (bookCon.State == ConnectionState.Open)
{
bookCom.Parameters.AddWithValue("#isbn", ISBN);
bookCom.Parameters.AddWithValue("#author", Author);
bookCom.Parameters.AddWithValue("#title", Title);
bookCom.Parameters.AddWithValue("#publisher", Publisher);
bookCom.Parameters.AddWithValue("#date", Date);
bookCom.Parameters.Add("#loan", SqlDbType.Char).Value = GetLoan; // didn't work at all
}
Is there any way I could get GetLoan to work?

You have to specify the return type in the function:
private string GetLoan(RadioButton radiobutton)
{
if (radiobutton.Checked)
{
return "yes";
}
else
{
return "no";
}
}
Or as a bool in one line of code:
private bool GetLoan(RadioButton radiobutton)
{
return radiobutton.Checked;
}
And then you always need to pass RadioButton as a parameter. So change
bookCom.Parameters.Add("#loan", SqlDbType.Char).Value = GetLoan;
To
bookCom.Parameters.Add("#loan", SqlDbType.Char).Value = GetLoan(rdbtn_Yes);
But why not make it easier and just check which one is selected:
String Loan = "no";
if (rdbtn_Yes.Checked == true)
{
Loan = "yes";
}
bookCom.Parameters.Add("#loan", SqlDbType.Char).Value = Loan;

By reading the snippet provided, I understand that you need to ask user if he/she is interested in loan.
Instead of radio buttons for yes or no, you could consider using a check box then use the below function.
private string GetLoan(CheckBox chkBxGetLoan)
{
//returns string value as output.
return chkBxGetLoan.Checked ? "Y" : "N";
}
OR
private char GetLoan(CheckBox chkBxGetLoan)
{
//returns char value as output.
return chkBxGetLoan.Checked ? 'Y' : 'N';
}

Related

ListItem.Selected returning false

I have a listbox with a list of items that get loaded when you navigate to a certain page. Then I have an on click that passes parameters to an AddProducts method. That method is what loops through all selected items and inserts values from the fields filled in as well as takes the values from the listItems and adds them as parameters to a stored procedure.
The problem I'm running into is that when looping through the listItems
if(selectedItem.Selected) is returning false, but in my method where I load the listbox I initialize a SelectedValue so I'm not sure why it's giving me the error message I have for no selected items. I was able to get it to work yesterday before I moved LoadListBoxCategories outside of LoadAddData but unsure as to why that would have any effect to if(listItem.Selected).
I'm relatively new to asp.net so any help/ explanation as to why my code isn't working is extremely appreciated. I've spent the last three days trying to figure this out and haven't found a solution that works.
Code:
Page_Load:
protected void Page_Load(object sender, EventArgs e)
{
if (Session[IS_LOGGED_IN] == null)
{
Response.Redirect("/utilities/companydata/login.aspx", true);
return;
}
gvTextInputs.RowEditing += new GridViewEditEventHandler(gvTextInputs_RowEditing);
if (!IsPostBack)
{
string pageId = Request.QueryString["pageid"];
string productId = Request.QueryString["productid"];
/* Add Mode */
if (!string.IsNullOrEmpty(pageId))
{
SetMode(MODE_ADD, "");
LoadAddData(pageId);
LoadListBoxCategories(pageId);
}
else if (!string.IsNullOrEmpty(productId))
{
string imageServer;
if (LoadProductData(productId, out imageServer))
{
InitImageGridview();
InitTextGridview();
InitStaticGridview();
SetMode(MODE_EDIT, imageServer);
SetImageServer(imageServer);
}
else
{
//TO DO - Return Error
}
}
}
else
{
InitImageGridview();
InitTextGridview();
InitStaticGridview();
}
}
Load ListBox:
private void LoadListBoxCategories(string pageId)
{
listBoxCategories.Visible = true;
//This gets query is so I can store the CompanyId and the CombinedValue data from pageId
string select = "SELECT companyName, cl.GbsCompanyId, cl.companyId, wpt.productTypeId, productName, (CAST(wp.pageId as varchar(200)) +'|'+ CAST(wp.productTypeId as varchar(200)) + '|' ) AS CombinedValue FROM CompanyList cl, WtpPages wp, WtpProductTypes wpt WHERE cl.companyId=wp.companyId AND wpt.productTypeId=wp.productTypeId AND wp.pageId=#pageId";
SqlDataSource connectionId = new SqlDataSource(DB_CONNECT, select);
connectionId.SelectParameters.Add("pageId", pageId);
DataView dView = (DataView)connectionId.Select(DataSourceSelectArguments.Empty);
if (dView.Table.Rows.Count == 1)
{
string companyId = dView.Table.Rows[0]["companyId"].ToString();
string curCategoryProductTypeId = dView.Table.Rows[0]["CombinedValue"].ToString();
// EXEC MCAdmin_GetAllCategoriesByCompanyId #companyId
// Lists All Categories #companyId has Active
string selectLoadData = "EXEC MCAdmin_GetAllCategoriesByCompanyId #companyId";
SqlDataSource conn = new SqlDataSource(DB_CONNECT, selectLoadData);
conn.SelectParameters.Add("companyId", companyId);
lstCategoriesBox.Items.Clear();
lstCategoriesBox.Items.Add(new ListItem("--Select--", null));
lstCategoriesBox.DataTextField = "productName";
lstCategoriesBox.DataValueField = "CombinedValue";
// Pre-selects the value of the productTypeId you are trying to add a product for
// to send later run against a foreach insert in AddProduct()
lstCategoriesBox.SelectedValue = curCategoryProductTypeId;
testOutcomeCategory.InnerText = curCategoryProductTypeId;
lstCategoriesBox.DataSource = conn;
lstCategoriesBox.DataBind();
}
}
AddProduct:
private string AddProduct(string companyId, out string errMsg)
{
foreach (ListItem selectedItem in lstCategoriesBox.Items)
{
if (selectedItem.Selected)
{
// assign current productTypeId & pageId from selected Categories new CombinedValue column
string[] splitColumnValue = selectedItem.Value.Split('|');
string selectedPageId = splitColumnValue[0].ToString();
string selectedProductTypeId = splitColumnValue[1].ToString();
SqlDataSource connnection = new SqlDataSource(DB_CONNECT, "");
connnection.InsertCommand = "EXEC MCAdmin_AddProductFromClassic #pageId, #productTypeId, #productCode, #imgDirectory, #numSides, #sortOrder, #isActive, #template, #template2, #template3, #EditorJson, #MockupTemplateBase, #MockupTemplateTreatment, #BorderDefault ";
connnection.InsertParameters.Add("pageId", selectedPageId);
connnection.InsertParameters.Add("productTypeId", selectedProductTypeId);
connnection.InsertParameters.Add("productCode", txtProductCode.Text);
connnection.InsertParameters.Add("numSides", ddlNumSides.SelectedValue);
connnection.InsertParameters.Add("sortOrder", txtSortOrder.Text);
connnection.InsertParameters.Add("isActive", ddlActive.SelectedValue);
connnection.InsertParameters.Add("template", txtTemplate1.Text);
connnection.InsertParameters.Add("template2", txtTemplate2.Text);
connnection.InsertParameters.Add("template3", txtTemplate3.Text);
connnection.InsertParameters.Add("EditorJson", txtJson.Text);
connnection.InsertParameters.Add("MockupTemplateBase", txtMockupTemplateBase.Text);
connnection.InsertParameters.Add("MockupTemplateTreatment", txtMockupTemplateTreatment.Text);
connnection.InsertParameters.Add("BorderDefault", txtBorderDefault.Text);
/* Special Product Code for Upload Artwork Business Card */
if (txtProductCode.Text.ToUpper() == "BPFAH1-001-100")
{
connnection.InsertParameters.Add("imgDirectory", "/images/business-cards/general/");
}
else
{
connnection.InsertParameters.Add("imgDirectory", ddlImgDir.SelectedValue);
}
int result = connnection.Insert();
if (result > 0)
{
SqlDataSource connect = new SqlDataSource(DB_CONNECT, "");
connect.SelectCommand = "SELECT TOP 1 wtpProductId FROM WtpProducts ";
connect.SelectCommand = "WHERE productTypeId=#productTypeId AND pageId=#pageId DESC ";
connect.SelectParameters.Add("pageId", selectedPageId); //
connect.SelectParameters.Add("productTypeId", selectedProductTypeId); //
DataView dView = (DataView)connect.Select(DataSourceSelectArguments.Empty);
if (dView.Table.Rows.Count == 1)
{
string wtpProductId = dView.Table.Rows[0]["wtpProductId"].ToString();
errMsg = "";
return wtpProductId;
}
else
{
errMsg = "ERROR: Could not get productId of newly created Product.";
return "0";
}
}
else
{
errMsg = "ERROR: Could not add WtpProduct record to DB";
return "0";
}
}
else
{
errMsg = "ERROR: You must select a Category";
return "0";
}
}
errMsg = "ERROR: Did not make it into the foreach loop";
return "0";
}
OnClick method:
protected void OnClick_btnAddProduct(object sender, EventArgs e)
{
string pageId = Request.QueryString["pageid"];
testOutcomeCategory.InnerText = lstCategoriesBox.SelectedValue; // This proves that I have something selected!!!
string select = "SELECT companyName, cl.GbsCompanyId, cl.companyId, wpt.productTypeId, productName, baseImgDirectory, templateDirectory, wp.imageServer FROM CompanyList cl, WtpPages wp, WtpProductTypes wpt WHERE cl.companyId=wp.companyId AND wpt.productTypeId=wp.productTypeId AND wp.pageId=#pageId";
SqlDataSource conn = new SqlDataSource(DB_CONNECT, select);
conn.SelectParameters.Add("pageId", pageId);
DataView dView = (DataView)conn.Select(DataSourceSelectArguments.Empty);
if(dView.Table.Rows.Count == 1)
{
string companyId = dView.Table.Rows[0]["companyId"].ToString();
if (!string.IsNullOrEmpty(pageId))
{
string errMsg;
string productId = AddProduct(companyId, out errMsg);
if(productId != "0")
{
Response.Redirect("/utilities/companydata/add-edit-wtp-product.aspx?productid=" + productId, true);
SetStatusMsg("Success", false);
}
else
{
SetStatusMsg(errMsg, true);
}
}
}
}
The list box instance is recreated on the server-side during the postback (as well as entire page). You do not set the selected items in the Page_Load event handler - if (!IsPostBack) goes to else branch. This is why you don't see them.
Ok,
lstCategoriesBox.Items.Clear();
Ok, above goes nuclear - blows out the list, blows out the selection.
Ok, that's fine
lstCategoriesBox.Items.Add(new ListItem("--Select--", null));
lstCategoriesBox.DataTextField = "productName";
lstCategoriesBox.DataValueField = "CombinedValue";
Ok, above adds a new item. Should be ok, but one should setup the lb BEFORE adding any data - including that "--select--" row.
It just makes sense to "setup" the lb and THEN start adding data, right?
However, But, if above works - ok, then lets keep going, but I would setup the lb before adding any rows of data. Say like this:
lstCategoriesBox.DataTextField = "productName";
lstCategoriesBox.DataValueField = "CombinedValue";
lstCategoriesBox.Items.Add(new ListItem("--Select--", null));
Now, the next line:
lstCategoriesBox.SelectedValue = curCategoryProductTypeId;
Ouch! - we just cleared the lb, and now we trying to set it to a value? You can't do that - the lb just been cleared, right? You would need to load up the lb first, and THEN you can set it to the selected value, right?
I might be missing something here, but that lb needs to be loaded up with valid data BEFORE you attempt to set the selected value?
To test first, change following
Outcome Category.InnerText = list CategoriesBox.SelectedValue;
to
Category.InnerText = Request.Form["CategoriesBox-ClientID"]
If the data is coming in correctly, the list view cleared or reloaded when between reload and click events the page.
UPDATE: I just figured it out! So stupid but when I check if(selectedItem.Selected) since I'm looping through the ListBox items it starts at the first index of the ListBox and since the first isn't selected then that if goes to the else block. Remove the else and it works fine

Get return List on 3 tiers

I need return List on textbox and others controls... In my Gridview the result is ok.
I use grv.Datasouce = method... Its ok. But i dont return single values.
public Configuracoes()
{
}
public int conId { get; set; }
public string conDescricao { get; set; }
}
}
public List<Configuracoes> GetConfiguracoes()
{
List<Configuracoes> list = new List<Configuracoes>();
using (SQLiteConnection conn = new SQLiteConnection(strAppDir))
{
conn.Open();
SQLiteCommand command = new SQLiteCommand("SELECT * FROM CAP_CONFIGURACAO ORDER BY conId", conn);
SQLiteDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Configuracoes configuracoes = new Configuracoes();
configuracoes.conDescricao = reader["conDescricao"].ToString();
list.Add(configuracoes);
}
}
return list;
}
how to return this for a text box ?
txt.Text = ?
your function returns an object of type List<Configuracoes>, now you want to set it to a textbox Text property wich is a string, there is not way in this world that can be possible.
what you can do is make a string of your array and set it in the Text property of your textbox. something like
var myConfigs = GetConfiguracoes();
string myString;
foreach(var config in myConfigs){
myString += config.conDescricao;
}
txt.Text = myString;
hope it helps
Got It !
I used DataBinding on my textbox
txtPastaProcessada.DataBindings.Add(new Binding("Text", ds, "columnoftable", false, DataSourceUpdateMode.OnPropertyChanged));

dropdownlist selected value is not changing?

dropdownlist selected value is not changing. although the string _month also contain the value but dropdownlist is not getting it.all other are working fine but only ddlMonth.selected value is not changing.i have assigned _month value to it but its not changing why? only ddlMonth is not changing all other are working fine why ddlmonth is not changing?
if (_objMonth.Contains("Month"))
{
string _Month = (string)_objMonth.GetData("Month");
ddlMonth.SelectedValue = _Month;
///here ddlMonth.selected value is not getting new value from _month
}
Other code is below
protected void Page_Load(object sender, System.EventArgs e)
{
if (Page.IsPostBack)
return;
try
{
OnLoad();
GetYears();
if (!string.IsNullOrEmpty(ddlYear.SelectedValue))
hYearId.Value = ddlYear.SelectedValue;
GetPeriods(Convert.ToInt32(hYearId.Value));
GetDepartment();
GetSection();
#region Get Selected login user department and section
ddldepartment.SelectedValue = CommonMethods.UserContext.EmployeeDeparmentID;
ddlSection.SelectedValue = CommonMethods.UserContext.EmployeeSectionID;
#endregion
ddldepartment_SelectedIndexChanged(null, null);
ddlemp_SelectedIndexChanged(null, null);
string name = Request.QueryString["id"] as string;
#region Create Cache object
ICacheManager _objYear = CacheFactory.GetCacheManager();//Create cache object
ICacheManager _objMonth = CacheFactory.GetCacheManager();//Create cache object
ICacheManager _objDepartment = CacheFactory.GetCacheManager();//Create cache object
ICacheManager _objSection = CacheFactory.GetCacheManager();//Create cache object
#endregion
if (Request.QueryString["ClickTag"]!=null)
{
#region set Cached items
if (Request.QueryString["ClickTag"].ToString() == "1")
{
if (_objYear.Contains("Year"))
{
string _Year = (string)_objYear.GetData("Year");
ddlYear.SelectedValue = _Year;
}
if (_objMonth.Contains("Month"))
{
string _Month = (string)_objMonth.GetData("Month");
ddlMonth.SelectedValue= _Month;
}
if (_objDepartment.Contains("Department"))
{
string _Department = (string)_objDepartment.GetData("Department");
ddldepartment.SelectedValue= _Department;
}
if (_objSection.Contains("Section"))
{
string _Section = (string)_objSection.GetData("Section");
ddlSection.SelectedValue = _Section;
}
}
#endregion
}
protected void ddlMonth_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (!string.IsNullOrEmpty(ddlMonth.SelectedValue))
{
hClpid.Value = ddlMonth.SelectedValue.Split(',')[0];
Session["Startdate"] = ddlMonth.SelectedValue.Split(',')[2];
Session["EndDate"] = ddlMonth.SelectedValue.Split(',')[3];
ddldepartment_SelectedIndexChanged(null, null);
ddlemp_SelectedIndexChanged(null, null);
if (ddlSection.SelectedIndex > 0)
ddlSection_SelectedIndexChanged(null, null);
}
}
void GetPeriods(int _year)
{
IBLCalenderPeriod _bl = (IBLCalenderPeriod)SetupBLFactory.GetCalenderPeriod();
DataSet _ds = (DataSet)_bl.GetPeriodIdsByYear(_year).GetMaster();
_ds.Tables[0].Columns.Add("ID");
foreach (DataRow _dr in _ds.Tables[0].Rows)
{
_dr["ID"] = _dr["CLP_ID"] + "," + _dr["clp_activeperiod"] + "," + _dr["CLP_DATESTART"] + "," + _dr["CLP_DATEEND"] + "";
}
ddlMonth.DataSource = _ds.Tables[0];
ddlMonth.DataTextField = "CLP_DESCRIPTION";
ddlMonth.DataValueField = "ID";
ddlMonth.DataBind();
foreach (DataRow _dr in _ds.Tables[0].Rows)
{
if (_dr["clp_activeperiod"] != null)
if (_dr["clp_activeperiod"].ToString() == "1")
{
ddlMonth.SelectedValue = _dr["ID"].ToString();
hClpid.Value = ddlMonth.SelectedValue.Split(',')[0];
Session["Startdate"] = ddlMonth.SelectedValue.Split(',')[2];
Session["EndDate"] = ddlMonth.SelectedValue.Split(',')[3];
break;
}
else
{
ddlMonth.SelectedIndex = 0;
hClpid.Value = "0";
}
}
}
I think you are setting a value in ddlMonth but ddlMonth do not have that binded value.. Try to bind list of values in your ddlMonth before setting a value to it
Please next time format the code before posting.
For the problem I think the solution is to put the region where you set the SelectedValue inside an
if(!isPostback){...}
I suggest you to take a look to the documentation about page lifecycle, because the explanation is that the Page_Load in executed not only the first time you load a page, but also for every postback (if you don't use the if(!isPostback){...}

Search multiple column using multiple control in asp.net using linq

Project_Detail pro = new Project_Detail();
string title=Ttitle.Text;
string year1=Tyear.Text;
string key = Tkeywrds.Text;
string area = Ddl_area.Text;
string categ = Ddl_catgry.Text;
string tech = Ddl_tech.Text;
string type =Ddl_type.Text;
var q = from obj in da.Project_Details
where obj.Project_Title.Contains(title)
|| obj.Submission_Date.Contains(year1)
|| obj.Keywords.Contains(key)
|| obj.Project_Area.Contains(area)
|| obj.Project_Category.Contains(categ)
|| obj.Project_Technology.Contains(tech)
|| obj.Project_Type.Contains(type)
select obj;
if (q != null)
{
DetailsView1.DataSource = q;
DetailsView1.DataBind();
}
else
{
Literal1.Text = "Data not found";
}
this code give last record of table and also not give else condition result.
I want result of all condition and want to use LIke satatement.
q is never null. It might be empty, though. So you should change your code to
if (q.Any()) // <<-----
{
DetailsView1.DataSource = q;
DetailsView1.DataBind();
}
else
{
Literal1.Text = "Data not found";
}
You can also use count method .Count()
if (q.count()>0)
{
DetailsView1.DataSource = q;
DetailsView1.DataBind();
}
else
{
Literal1.Text = "Data not found";
}

Creating tooltip for multiple buttons

This code(below) suppose to add information to ToolTips which are taken from database(and the class Codons does it(it is the part that actually works)). I tried to do it in FOR loop, but it is warning me about this line:
toolTip1.SetToolTip(Convert.ToString(letter),"Name: "+fullname+" ("+cdn.GetCodon1()+")"
+"\n Begin: "+cdn.GetStart()+", End: "+cdn.GetEnd()+"");
I have 20 buttons which are named in a-z letters, except 6 specific letters(see the IF inside the FOR)
Here is the CODE:
private void UpdateToolTipButton()
{
string fullname;
Codons cdn;
char letter='a';
//get info about every amino acid from database
OleDbConnection dataConnection = new OleDbConnection();
dataConnection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Projects_2012\\Project_Noam\\Access\\myProject.accdb";
dataConnection.Open();
for(int i=1;i<=26;i++,letter++)
{
if((letter!='b')&&(letter!='e' )&& (letter!='j') && (letter!='o')&& (letter!='u') && (letter!='z'))
{
OleDbCommand datacommand = new OleDbCommand();
datacommand.Connection = dataConnection;
datacommand.CommandText = "SELECT tblCodons.codonsFullName"
+" FROM tblCodons"
+" WHERE tblCodons.codonsCodon1="+letter;
OleDbDataReader dataReader = datacommand.ExecuteReader();
dataReader.Read();
fullname = dataReader.GetString(0);
cdn = new Codons(fullname);
toolTip1.SetToolTip(Convert.ToString(letter),"Name: "+fullname+" ("+cdn.GetCodon1()+")"
+"\n Begin: "+cdn.GetStart()+", End: "+cdn.GetEnd()+"");
}
}
}
SetToolTip is looking for a control as the first argument. You are supplying Convert.ToString(letter).
The first argument needs to be the button you want to have the tooltip:
toolTip1.SetToolTip(button1, "Name: " + fullname);
I'm guessing you were trying to set the title of the ToolTip, in which case, that's not part of the SetToolTip method. You would have to set the property yourself:
toolTip1.ToolTipTitle = Convert.ToString(letter);
If your buttons are those letters, then you would reference them by their name as the control key:
if (this.Controls.ContainsKey(Convert.ToString(letter))) {
toolTip1.SetToolTip(this.Controls[Convert.ToString(letter)], "Name: " + fullname + " etc(";
}
You shouldn't open a new reader for every item, you were also missing single quotes around an item in the where clause, but the where clause isn't necessary anyway \(^_^)_/
anyway, this is my Solution.
private char _letter;
private string _fullName;
public char Letter{
get{
return _letter;
}
set{
_letter = value;
}
}
public string FullName{
get{
return _fullName;
}
set{
_fullName = value;
}
}
Private Void UpdateToolTipButton(){
string fullname;
codons cdn;
char letter;
OleDbConnection iConnect = new OleDbConnection();
iConnect.ConnectionString = #"Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=#"C:\Projects_2012\Project_Noam\Access\myProject.accdb";
OleDbCommand iCommand = new OldDbCommand("Select * from tblCodons",iConnect);
List<YourClassName> iList = new List<YourClassName>();
OleDbDataReader iRead = null;
iRead = iCommand.ExecuteReader();
while(iRead.Read()){
YourClassName iClass = new YourClassName();
iClass.Letter = Convert.ToChar(iRead["codonsCodon1"]);
iClass.FullName = Convert.ToString(iRead["codonsFullName"]);
iList.Add(iClass);
}
iConnect.Close();
iRead.Close();
foreach(var VarName in iList)
{
toolTip1.SetToolTip(button1, "Name: " + var.FullName);
toolTip1.ToolTipTitle = var.Letter;
}
}
If I got it right, your Form has multiple buttons, with their Text properties set to letters a-z. the problem is that SetToolip needs the control (button) as its first parameter in order to set its tooltip, but you are passing button's text value instead.
Your loop should be arranged into something like this, so that you can iterate through actual buttons:
foreach (var button in GetButtons())
{
if (ShouldSetTooltip(button))
{
// ...
tooltip.SetTooltip(button, text);
}
}
To get all buttons placed in your form (or on a panel), you can use something like:
private IEnumerable<Button> GetButtons()
{
// this is where you decide which buttons to return
foreach (var c in this.Controls) // or panel1.Controls
if (c is Button)
yield return (Button)c;
}
And then you will probably need to add your check to skip certain button names:
private bool ShouldSetTooltip(Control c)
{
string[] lettersToSkip = new string[] { "b","e","o","u","j","z" };
return lettersToSkip.Contains(c.Text) == false;
}
[Edit]
If you want to get the control by its Name property (note: this is not the same as the Text property), you can use you loop and write it like this:
for (int i = 1; i <= 26; i++, letter++)
{
...
var button = this.Controls[letter.ToString()];
var txt = "Name: "+fullname+" ("+cdn.GetCodon1()+")"
+"\n Begin: "+cdn.GetStart()+", End: "+cdn.GetEnd()+"";
toolTip1.SetToolTip(button, txt);
}

Categories