Click here to Skip to main content
15,867,835 members
Home / Discussions / C#
   

C#

 
GeneralRe: While button is clicked Pin
CHill6020-Apr-16 1:25
mveCHill6020-Apr-16 1:25 
GeneralRe: While button is clicked Pin
koolprasad200320-Apr-16 1:33
professionalkoolprasad200320-Apr-16 1:33 
AnswerRe: While button is clicked Pin
CHill6020-Apr-16 2:14
mveCHill6020-Apr-16 2:14 
PraiseRe: While button is clicked Pin
tvks20-Apr-16 10:57
tvks20-Apr-16 10:57 
GeneralRe: While button is clicked Pin
CHill6020-Apr-16 11:01
mveCHill6020-Apr-16 11:01 
GeneralRe: While button is clicked Pin
tvks27-Apr-16 2:55
tvks27-Apr-16 2:55 
QuestionReflection and "security" Pin
Super Lloyd19-Apr-16 7:17
Super Lloyd19-Apr-16 7:17 
QuestionLinkButton isnt recognized properly Pin
Collectoons19-Apr-16 4:19
Collectoons19-Apr-16 4:19 
Im very new to C# and am trying to use conversion tools to change some VB over. Im not quite sure how to remedy this error, so any help I can get is greatly appreciated!

This is the error Im receiving:

"CS0266: Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.LinkButton'. An explicit conversion exists (are you missing a cast?)"

for Line 93

C#
myDeleteButton = myTableCell.Controls[0];



Here is the full C# code:

C#
public void Page_Load(object Source, EventArgs E)
{
	if (!Page.IsPostBack)
	{
		BindData();
	}
}

public void BindData()
{
	DataSet myDataSet = new DataSet();
	SqlDataAdapter mySqlDataAdapter = default(SqlDataAdapter);
	mySqlDataAdapter = new SqlDataAdapter("SELECT * FROM glmaster", "REMOVED;");
	mySqlDataAdapter.Fill(myDataSet, "glmaster");
	glmasterInfo.DataSource = myDataSet.Tables["glmaster"];
	glmasterInfo.DataBind();
}

public void DataGrid_Delete(object Source, DataGridCommandEventArgs E)
{
	SqlConnection myConnection = default(SqlConnection);
	SqlCommand myCommand = default(SqlCommand);
	string strDeleteStmt = "";
	
	decimal balance_test = new decimal();
	string Balance_output = "";
	
	balance_test = System.Convert.ToDecimal(Convert.ToDecimal(E.Item.Cells[6].Text));
	
	if (balance_test == 0.0M)
	{
		outError.InnerHtml = "";
		strDeleteStmt = "DELETE FROM glmaster " + 
			" WHERE major = " + E.Item.Cells[1].Text + 
			" AND minor = " + E.Item.Cells[2].Text + 
			" AND sub1 = " + E.Item.Cells[3].Text + 
			" AND sub2 = " + E.Item.Cells[4].Text;
		try
		{
			myConnection = new SqlConnection(
				"REMOVED;");
			myCommand = new SqlCommand(strDeleteStmt, myConnection);
			myConnection.Open();
			myCommand.ExecuteNonQuery();
			
			glmasterInfo.EditItemIndex = -1;
			BindData();
		}
		catch (Exception exc)
		{
			outError.InnerHtml = "* Error while deleting data.<br />" 
				+ exc.Message + "<br />" + exc.Source;
		}
		finally
		{
			myConnection.Close();
		}
	}
	else
	{
		Balance_output = balance_test.ToString("C");
		string Error_String = "";
		
		Error_String = "<center>You Can\'t Delete This Account<br>";
		Error_String = Error_String + "Balance is NOT zero.<br>";
		Error_String = Error_String + "The Account Balance is " + Balance_output;
		Error_String = Error_String + " for ";
		Error_String = Error_String + E.Item.Cells[1].Text + "-";
		Error_String = Error_String + E.Item.Cells[2].Text + "-";
		Error_String = Error_String + E.Item.Cells[3].Text + "-";
		Error_String = Error_String + E.Item.Cells[4].Text + "</center>";
		
		outError.InnerHtml = Error_String;
	}
}

public void DataGrid_ItemCreated(object Sender, DataGridItemEventArgs e)
{
	if (((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem)) || (e.Item.ItemType == ListItemType.EditItem))
	{
		TableCell myTableCell = default(TableCell);
		myTableCell = e.Item.Cells[0];

		LinkButton myDeleteButton = default(LinkButton);
		myDeleteButton = myTableCell.Controls[0];
		myDeleteButton.Attributes.Add("onclick", "javascript: return confirm(\'Are you Sure you want to delete this account?\');");
	}
}


modified 19-Apr-16 11:29am.

SuggestionRe: LinkButton isnt recognized properly Pin
Richard MacCutchan19-Apr-16 5:09
mveRichard MacCutchan19-Apr-16 5:09 
GeneralRe: LinkButton isnt recognized properly Pin
Collectoons19-Apr-16 5:16
Collectoons19-Apr-16 5:16 
GeneralRe: LinkButton isnt recognized properly Pin
Richard MacCutchan19-Apr-16 5:26
mveRichard MacCutchan19-Apr-16 5:26 
AnswerRe: LinkButton isnt recognized properly Pin
Richard Deeming19-Apr-16 5:56
mveRichard Deeming19-Apr-16 5:56 
GeneralRe: LinkButton isnt recognized properly Pin
Collectoons19-Apr-16 6:03
Collectoons19-Apr-16 6:03 
GeneralRe: LinkButton isnt recognized properly Pin
Richard Deeming19-Apr-16 6:06
mveRichard Deeming19-Apr-16 6:06 
GeneralRe: LinkButton isnt recognized properly Pin
Collectoons19-Apr-16 6:08
Collectoons19-Apr-16 6:08 
QuestionError Starting Windows Service Pin
Member 1098552419-Apr-16 2:52
Member 1098552419-Apr-16 2:52 
AnswerRe: Error Starting Windows Service Pin
Eddy Vluggen19-Apr-16 2:57
professionalEddy Vluggen19-Apr-16 2:57 
QuestionSocket Example UWP Pin
Miwin Solutions19-Apr-16 1:13
Miwin Solutions19-Apr-16 1:13 
AnswerRe: Socket Example UWP Pin
Jochen Arndt19-Apr-16 2:18
professionalJochen Arndt19-Apr-16 2:18 
GeneralRe: Socket Example UWP Pin
Miwin Solutions20-Apr-16 2:16
Miwin Solutions20-Apr-16 2:16 
GeneralRe: Socket Example UWP Pin
Jochen Arndt20-Apr-16 2:58
professionalJochen Arndt20-Apr-16 2:58 
GeneralRe: Socket Example UWP Pin
Miwin Solutions20-Apr-16 3:52
Miwin Solutions20-Apr-16 3:52 
GeneralRe: Socket Example UWP Pin
Jochen Arndt20-Apr-16 3:59
professionalJochen Arndt20-Apr-16 3:59 
QuestionHow to login to a website programmatically using C#.? Pin
mbatra3118-Apr-16 23:58
mbatra3118-Apr-16 23:58 
AnswerRe: How to login to a website programmatically using C#.? Pin
Sascha Lefèvre19-Apr-16 0:06
professionalSascha Lefèvre19-Apr-16 0:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.