-1

I want use "Random rnd = new Random();"

public int dzien;

private void generator_Tick(object sender, EventArgs e)
{
 Random rnd = new Random();

 dzien = rnd.Next(1, 11);      
 webBrowser1.Document.GetElementById("birthDateDay").SetAttribute("value", dzien);
}

And when i want run program i got error:

cannot convert from 'int' to 'string'

This is in line "webBrowser1...." on "dzien".

Jonas
  • 121,568
  • 97
  • 310
  • 388
  • 3
    You almost certainly do not want to create a new Random each Tick – Ňɏssa Pøngjǣrdenlarp Dec 24 '16 at 20:45
  • Please make sure to read [MCVE] guidance before asking future questions - i.e.sample code for this question should be single line: `string valueForSetAttribute = 42;` (not that would make question on-topic on SO as searching for exact title of the post or error message would give you an answer already - https://www.bing.com/search?q=C%23+cannot+convert+from+%27int%27+to+%27string%27) – Alexei Levenkov Dec 24 '16 at 21:18

3 Answers3

4

Change dzien to dzien.ToString(). The SetAttribute method takes a string and you're trying to pass an integer to it.

negacao
  • 1,244
  • 8
  • 17
0

Replace dzien with dzien.ToString(). The setAttribute function requires two strings as arguments but you've given it a string and an integer.

0

This happening because setAttribute() method wants string as parameters and it not able to implicitly convert int to string. So simple replace your code with below line of code.

webBrowser1.Document.GetElementById("birthDateDay").SetAttribute("value", ""+dzien); 
Akshay Khanna
  • 56
  • 1
  • 7