PDA

View Full Version : کنترل تعریف شده داخل gridview در قسمت behind code شناخته نمیشه



elham1611
پنج شنبه 13 مهر 1391, 03:52 صبح
با سلام
من در داخل item template در گرید ویو یک label تعریف کردم اما چرا این label در قسمت behind code شناخته نمیشه ؟

amirzandi
پنج شنبه 13 مهر 1391, 08:25 صبح
بستگی داره تو چه eventi بخواین ازش استفاده کنین... به مثال زیر توجه کنید :


Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
CType(e.Row.FindControl("Label1"), Label).Text = "String"
End If

amirzandi
پنج شنبه 13 مهر 1391, 08:27 صبح
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Ctype(Me.GridView1.Rows(1).FindControl("Label1"),Label).Text = "String"
End Sub

elham1611
پنج شنبه 13 مهر 1391, 12:48 عصر
در یک event مربوط به dropdown
protected void dropdown1_SelectedIndexChanged(object sender, EventArgs e)
{

}

fakhravari
پنج شنبه 13 مهر 1391, 15:52 عصر
سوالت دقیقا چی؟
با پست 4 که دادی قاطی کردم چی میخواهی

elham1611
پنج شنبه 13 مهر 1391, 16:10 عصر
سوالک کلیه . منظورم اینه که چرا وقتی یک کنترل (مثلا label) داخل گریدویو (مثلا داخل itemtemplate) تعریف میکنیم در داخل code behind یا همان apx.cs شناخته نمیشه

fakhravari
پنج شنبه 13 مهر 1391, 18:39 عصر
مثل اینکه ما ادامس بخوریم بعد پوستشو بدیم به یکی دیگه بگیم بیا این ادامس برای تو.
هر کنترلی در داخل کنترل دیگه با متد find control باید پیدا کرد.