PDA

View Full Version : obtain custome properties



Farhad.B.S
پنج شنبه 29 آبان 1382, 20:22 عصر
سلام.
فرض کنید یه دیتا گرید داریم که در ستون اول اون قراره یه چک باکس قرار بگیره ، و این چک باکس هم توسط کاربر مقدار دهی میشه... حالا چطور میشه وضعیت چک باکس مربوط به هر سطر رو بدست آورد ؟

ممنون. :roll:

Vahid_Nasiri
پنج شنبه 29 آبان 1382, 23:17 عصر
شما ابتدا یک ایندکسر باید به صورت زیر تعریف کنید:


public Int32[] SelectedIndexes
{
get
{
System.Collections.ArrayList selectedIndexList = new System.Collections.ArrayList();

foreach( DataGridItem item in DataGrid1.Items )
{
Control foundControl = item.FindControl("chkHRow");
CheckBox Checkselector = foundControl as CheckBox;
RadioButton radioselector = foundControl as RadioButton;
if ( Checkselector != null && Checkselector.Checked )
{
selectedIndexList.Add( item.ItemIndex );
}
else if ( radioselector != null && radioselector.Checked )
{
selectedIndexList.Add( item.ItemIndex );
}
}
return (Int32[])selectedIndexList.ToArray(typeof( System.Int32 ) );
}
}

در کد فوق chkHRow نام همان چک باکس است...

سپس از ایندکسر فوق به صورت زیر استفاده می شود:


foreach(int i in SelectedIndexes )
myFunc(i+1);

Farhad.B.S
جمعه 30 آبان 1382, 11:08 صبح
خیلی ممنون.