PDA

View Full Version : سوال: اضافه کردن یک سطر به grid view



hamid mabhoot
جمعه 19 خرداد 1391, 00:55 صبح
سلام
من توپروژم از گریدویو دولاپ ویژوال 2010 استفاده می کنم حالا می خوام با استفاده از کدنویسی نه wizard یک ستون به gridviewاضافه کنم که لینک باشه به صورتیکه جلوی هر سطرم که یک لینک ایجاد شدid اون سطرو باquery string بگیره وبا کلیک بر روی اون لینک به صفحه مورد نظربره.لطفا اگر مطلبی دارید راهنماییم کنید ممنون میشم.

fa_karoon
جمعه 19 خرداد 1391, 08:37 صبح
سلام تو این پروژه من گرید ویوم رو با SQLDataSource پر کردم اما شما می تونی به هر طریقی که دوست داری این کار رو انجام بدی،
تو این پروژه من یه عکس رو لینک کردم و ID اون سطر رو به صورت QueryString بهش نسبت دادم ، این فقط یه نمونه است شما می تونی به طرق مختلف تغییرش بدی

macdlcom
یک شنبه 06 اسفند 1391, 12:07 عصر
سلام تو این پروژه من گرید ویوم رو با SQLDataSource پر کردم اما شما می تونی به هر طریقی که دوست داری این کار رو انجام بدی،
تو این پروژه من یه عکس رو لینک کردم و ID اون سطر رو به صورت QueryString بهش نسبت دادم ، این فقط یه نمونه است شما می تونی به طرق مختلف تغییرش بدی

کد مربوطه در C#‎‎

// Define the Columns.
colDef1 = new ColumnDefinition();
colDef1.Width = new GridLength(1, GridUnitType.Auto);
colDef2 = new ColumnDefinition();
colDef2.Width = new GridLength(1, GridUnitType.Star);
colDef3 = new ColumnDefinition();
colDef3.Width = new GridLength(1, GridUnitType.Star);
colDef4 = new ColumnDefinition();
colDef4.Width = new GridLength(1, GridUnitType.Star);
colDef5 = new ColumnDefinition();
colDef5.Width = new GridLength(1, GridUnitType.Star);
grid1.ColumnDefinitions.Add(colDef1);
grid1.ColumnDefinitions.Add(colDef2);
grid1.ColumnDefinitions.Add(colDef3);
grid1.ColumnDefinitions.Add(colDef4);
grid1.ColumnDefinitions.Add(colDef5);

// Define the Rows.
rowDef1 = new RowDefinition();
rowDef1.Height = new GridLength(1, GridUnitType.Auto);
rowDef2 = new RowDefinition();
rowDef2.Height = new GridLength(1, GridUnitType.Auto);
rowDef3 = new RowDefinition();
rowDef3.Height = new GridLength(1, GridUnitType.Star);
rowDef4 = new RowDefinition();
rowDef4.Height = new GridLength(1, GridUnitType.Auto);
grid1.RowDefinitions.Add(rowDef1);
grid1.RowDefinitions.Add(rowDef2);
grid1.RowDefinitions.Add(rowDef3);
grid1.RowDefinitions.Add(rowDef4);

// Add the Image.
img1 = new Image();
img1.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("runicon.png", UriKind.Relative));
Grid.SetRow(img1, 0);
Grid.SetColumn(img1, 0);

// Add the main application dialog.
txt1 = new TextBlock();
txt1.Text = "Type the name of a program, folder, document, or Internet resource, and Windows will open it for you.";
txt1.TextWrapping = TextWrapping.Wrap;
Grid.SetColumnSpan(txt1, 4);
Grid.SetRow(txt1, 0);
Grid.SetColumn(txt1, 1);

// Add the second text cell to the Grid.
txt2 = new TextBlock();
txt2.Text = "Open:";
Grid.SetRow(txt2, 1);
Grid.SetColumn(txt2, 0);

// Add the TextBox control.
tb1 = new TextBox();
Grid.SetRow(tb1, 1);
Grid.SetColumn(tb1, 1);
Grid.SetColumnSpan(tb1, 5);

// Add the buttons.
button1 = new Button();
button2 = new Button();
button3 = new Button();
button1.Content = "OK";
button2.Content = "Cancel";
button3.Content = "Browse ...";
Grid.SetRow(button1, 3);
Grid.SetColumn(button1, 2);
button1.Margin = new Thickness(10, 0, 10, 15);
button2.Margin = new Thickness(10, 0, 10, 15);
button3.Margin = new Thickness(10, 0, 10, 15);
Grid.SetRow(button2, 3);
Grid.SetColumn(button2, 3);
Grid.SetRow(button3, 3);
Grid.SetColumn(button3, 4);

grid1.Children.Add(img1);
grid1.Children.Add(txt1);
grid1.Children.Add(txt2);
grid1.Children.Add(tb1);
grid1.Children.Add(button1);
grid1.Children.Add(button2);
grid1.Children.Add(button3);

mainWindow.Content = grid1;