PDA

View Full Version : چطور میتونم به کنترل های داخل بخش ItemTemplate از کنترل GridView دسترسی پیدا کنم؟



baha_film
جمعه 20 خرداد 1390, 23:37 عصر
در مورد رویدادهای GridView1_RowCancelingEdit و GridView1_RowUpdating و GridView1_RowEditing راهنمایی کنید چون میخوام سطرهای GridView رو ویرایش کنم ولی نمیتونم به Id کنترل هایی که تو ItemTemplate گذاشتم دسترسی پیدا کنم
اصلا چطور باید به کنترل های داخل GridView باید دسترسی داشته باشم مثلا TextBox1.Text یا Label1 یا Button1
ممنون

mohammadyaser
شنبه 21 خرداد 1390, 09:11 صبح
ببین این کمکت می کنه؟protected void ToggleRowSelection(object sender, EventArgs e)
{
((sender as CheckBox).NamingContainer as GridItem).Selected = (sender as CheckBox).Checked;
}
protected void ToggleSelectedState(object sender, EventArgs e)
{
CheckBox headerCheckBox = (sender as CheckBox);
foreach (GridDataItem dataItem in RadGrid1.MasterTableView.Items)
{
(dataItem.FindControl("CheckBox1") as CheckBox).Checked = headerCheckBox.Checked;
dataItem.Selected = headerCheckBox.Checked;
}
}

sam166
شنبه 21 خرداد 1390, 12:00 عصر
بدست آوردن ID سطر گرید ویو
GridViewRow row = (GridViewRow)((Control)e.CommandSource).Parent.Par ent;

int rowid = row.DataItemIndex;

دسترسی به کنترل داخل گرید ویو
DropDownList ddl = (DropDownList)GridView2.Rows[rowid].Cells[3].FindControl("DropDownList1");
string val = ddl.SelectedValue;

Saber_Fatholahi
شنبه 21 خرداد 1390, 13:44 عصر
سلام دوست من با يه حلقه اول سطرهاي گريد ويو پيمايش كن اون سطر هايي كه از نوع ديتا هست بررسي كن
بعد با استفاده از FindControl گزينه مورد نظرتو پيدا كن و اعمال مورد نظرتو بهش بده
foreach (GridViewRow row in GridView1.Rows ent;

if (row.RowType == DataRowType)
{
row.FindControl,...
}
{
;
}
مويد باشيد

abbas3zaar
یک شنبه 20 فروردین 1391, 02:18 صبح
85421

عکس بالا رو ببنید
با SQLDataSource چجوری یک سطر از GridView رو حذف کنم؟
یک ستون با عنوان "حذف" گذاشتم و یک Button گذاشتم. آیا باید در رویداد rowCommand کد بنویسم؟ دستورش چیه؟

sarapepors
یک شنبه 20 فروردین 1391, 12:24 عصر
باید برای این فیلد که از نوع button هست یه comandname در نظر بگیرید و درخاصیت rowcommand گرید ویو کد بنویسید:

int index = int.Parse(e.CommandArgument.ToString());
Label lablel_id = (Label)GridView_Kala.Rows[index].Cells[0].FindControl("lblid");


به عنوان مثال lblid شناسه label مرتبط با کد گروهتون در گرید ویو هست خوب حالا شما با خوندن خاصیت text مربوط به label_id میتونید کد گروهتون رو بخونید و با یک کوئری حذف اون رو حذف کنید و مجددا گرید ویو رو بایند کنید تا دوباره رکورد حذف شده رو نمایش نده.

mohsen.nsb44
یک شنبه 20 فروردین 1391, 12:59 عصر
دوستان من یک چک باکس در قسمت تمپلیت گزاشتم که اگه تیک خورد عملی رو با دکمه انجام بدو
کد زیر رو برای پیدا کردن کنترل چک باکس نوشتم اما کار نمیکنه


CheckBox ddl = (CheckBox)GridView1.SelectedRow.FindControl("CDelete");

fakhravari
یک شنبه 20 فروردین 1391, 13:23 عصر
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.ToLower() == "showinfo")
{
foreach (GridViewRow row in GridView1.Rows) // Loop In All Grid Row To Find Clicked Row Labels
{
int currentRecordId = int.Parse(((HiddenField)row.FindControl("hflRowID")).Value); // Current GridRow
int pressedRecordId = int.Parse(e.CommandArgument.ToString()); // Clicked GridRow Data

if (currentRecordId == pressedRecordId) // Clicked Row Found !
{
Label label1 = (Label)row.FindControl("Label1"); // !
Label label2 = (Label)row.FindControl("Label2");
Label label3 = (Label)row.FindControl("Label3");


TextBox1.Text = label1.Text;
TextBox2.Text = label2.Text;
TextBox3.Text = label3.Text;

return; // Exit Loop
} // if
} // Foreach
}
}
}

sarapepors
یک شنبه 20 فروردین 1391, 16:05 عصر
دوستان من یک چک باکس در قسمت تمپلیت گزاشتم که اگه تیک خورد عملی رو با دکمه انجام بدو
کد زیر رو برای پیدا کردن کنترل چک باکس نوشتم اما کار نمیکنه


CheckBox ddl = (CheckBox)GridView1.SelectedRow.FindControl("CDelete");



foreach (GridViewRow gvr in GridView_News_Comment.Rows)
{
Chk = (CheckBox)gvr.FindControl("Chk");
Lbl = (Label)gvr.FindControl("NewsComment_id");
if (Chk.Checked)
{
SelectedRows += Lbl.Text + ",";
objNewsComment.New_Comment_id = Int64.Parse(Lbl.Text);
objNewsComment.Delete();
}
}
این یه قسمت از کد برنامه ایه که نوشتم Chk , lbl رو هم از قبل از نوع label , checkbox تعریف کردم.

rezaei manesh
چهارشنبه 13 اردیبهشت 1391, 10:56 صبح
این دستورات شما فقط زمانی کنترل درون رکورد های گراید رو پیدا می کنه که از طریق کد نویسی ساخته نشده باشه
من کل کنترل های گرایت رو موقع لود گراید با کد نویسی می سازم و مشکل اینجاست که زمانی که از این روش استفاده می کنم کنترل ها پیدا نمی شن

sahar15125
چهارشنبه 09 اسفند 1391, 07:41 صبح
من با ین روش کار کردم :

int mId;
protected void GrdLuck_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Edit")
{
mId = int.Parse(e.CommandArgument.ToString());
ViewState["mId"] = mId;
}
if (e.CommandName == "Delete")
{
mId = int.Parse(e.CommandArgument.ToString());
}
}
protected void GrdLuck_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string str1 = string.Format("UPDATE LuckDates SET IsDeleted={0} WHERE Id={1}", 1,mId);
dbc.executecmd(str1);
BindGrdLuck();
BindgGrdDeleted();

}
protected void GrdLuck_RowEditing(object sender, GridViewEditEventArgs e)
{

string EditId = "Edit.aspx?Id=" + mId;
Response.Redirect(EditId);

}