Hi,
have for example 4 variables:
string myvar1="one"
string myvar2="two"
string myvar3="three"
string myvar4="four"
now I want to use the value from variable myvar3, somehow like this:
string mynewvar = "myvar"+"3"
now I would have the value "three" assigned to my new variable.
Is something like that possible?
Cheers,
Loading
Suthish NairPosted Jan 30, 2011, 1:23 PM
So other members can easily find the answers.
Sam HobbsPosted Jan 27, 2011, 3:42 PM
Bryian TanPosted Jan 27, 2011, 11:58 AM
I think I know what you looking for. Try the following example. I have 4 buttons on the page and assign the click event to it dynamically.
.aspx page
.aspx.cs page
protected void Page_Load(object sender, EventArgs e)
{
Btn_Assign_Event();
}
void Btn_Assign_Event()
{
for (int i = 1; i < 5; i++)
{
Button myAllButtons = new Button();
myAllButtons = Page.FindControl("Button" + i.ToString()) as Button;
myAllButtons.Click += new EventHandler(myAllButtons_Click);
}
}
void myAllButtons_Click(object sender, EventArgs e)
{
Button clickedButton = (Button)sender;
Label2.Text = "you clicked on " + clickedButton.ID;
}
if you are using MasterPage. use this method
void Btn_Assign_Event()
{
ContentPlaceHolder mpContentPlaceHolder;
mpContentPlaceHolder = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
if (mpContentPlaceHolder != null)
{
for (int i = 1; i < 5; i++)
{
Button myAllButtons = new Button();
myAllButtons = mpContentPlaceHolder.FindControl("Button" + i.ToString()) as Button;
myAllButtons.Click += new EventHandler(myAllButtons_Click);
}
}
}
Suthish NairPosted Jan 27, 2011, 11:25 AM
Explain your thread with proper information so that we can help you.
Both your posts are different.
Maik BrauerPosted Jan 27, 2011, 10:02 AM
In order to make the code shorter an not to create a separate Click event I decided to concatonate this values:
here some vb.net code: dim myvalue as string = grpTable.Controls("mybutton" + "1").Tag
after this I had the TAG from button "mybutton1" stored in variable myvalue.
Sriram KrishnanPosted Jan 27, 2011, 9:54 AM