2
我有一個問題,我有一些動態button.and我想存儲整數值。如何在運行時在按鈕中存儲值?
,並獲得該按鈕的那個點擊事件值我怎麼能實現它提前 沙善
DataView dv = new DataView(dtCat, "PK_CATEGORY_ID IN(" + categoryIds.ToString() + "0)", "PK_CATEGORY_ID", DataViewRowState.CurrentRows);
foreach (DataRowView rr in dv)
{
//MessageBox.Show(rr[0].ToString() + "------------" + rr[1].ToString());
Button b2 = new Button();
//b2.Name = rr[0].ToString();
b2.Name = "";
b2.Height = 200;
b2.Width = 200;
b2.Margin = new Thickness(0, -100, 0, 0);
b2.HorizontalAlignment = HorizontalAlignment.Left;
b2.Content = rr[1].ToString();
b2.Background = System.Windows.Media.Brushes.Pink;
b2.Click += new RoutedEventHandler(b2_Click);
btncanvas.Children.Add(b2);
Canvas.SetLeft(b2, b2.Width * i);
i = i + 1;
MessageBox.Show(rr[0].ToString());
b2.Tag = rr[0].ToString();
}
void b2_Click(object sender, RoutedEventArgs e)
{
Button clicked = (Button)sender;
categoryname = clicked.Name;
}
但其給出錯誤that..Specified轉換是無效的。 – Shashank 2010-06-14 11:08:42
thk它工作 – Shashank 2010-06-14 11:13:57
@SHASHANK - 我已經糾正了代碼。我打字時沒有訪問Visual Studio;) – ChrisF 2010-06-14 11:14:06