PDA

View Full Version : مبتدی: مشكل در استفاده از گريد ويو



nassim0
سه شنبه 27 اردیبهشت 1390, 12:46 عصر
با سلام
دوستان من يك گريدويو دارم كه با item template اون نحوه چيدمان ليبل هام رو انجام دادم (فيلد تمپليت)و bind هم كردم الان ميخوام با كليك روي يك image botton كه داخل گريدويو تعريف شده كد آگهي رو به صفحه بعد بفرستم . اين كارو با session انجام دادم اما فقط آخرين ركورد بانكم رو مي فرسته از كد زير استفاده كردم تا متن ليبل(كد آگهي) مورد نظرم روپيدا كنه اما error ميده .من حتي نميدونم ليبل 7 توي كدوم سلوله وقتي كه تمپليت تعريف كردم .لطفا منو راهنمايي كنيد.

Label lb = (Label)GridView3.SelectedRow.Cells[5].FindControl("Label7");

Label8.Text = lb.Text.ToString();

b.paseban
سه شنبه 27 اردیبهشت 1390, 13:06 عصر
سلام بر شما.
شما باید از query string استفاده کنید.سرچ بزنید توی سایت نمونه زیاده.

nassim0
سه شنبه 27 اردیبهشت 1390, 13:24 عصر
من چطور مي تونم از رديف هاي گريدويو كد آگهي جاري رو انتخاب كنم

b.paseban
سه شنبه 27 اردیبهشت 1390, 14:01 عصر
http://barnamenevis.org/showthread.php?278140-%D9%85%D8%AF%DB%8C%D8%B1%DB%8C%D8%AA-%D8%A7%D8%AE%D8%A8%D8%A7%D8%B1&p=1227335&highlight=#post1227335

dontspeak
سه شنبه 27 اردیبهشت 1390, 15:49 عصر
شما از همون session استفاده کنی بهتره. sission رو در هر بار انتخاب یک آیتم گرید ویو آپدیت کن مثلا به این کد نگاه کن
protected void gvCart_SelectedIndexChanged(object sender, EventArgs e)
{
// this method is actually hooked to the Remove button &
// is removing items from the cart
string strProductID = gvCart.SelectedRow.Cells[1].Text;
if (Session["Cart"] != null)
{
// remove the selected ProductID from the Session string
// Retrieve the session string.
string strCart = Session["Cart"].ToString();
string[] arIDs = strCart.Split(new Char[] { ',' });
// iterate through the ID's comprising the string array
// rebuild the cart string, leaving out the matching ID
strCart = string.Empty;
foreach (string str in arIDs)
{
// use Trim to remove leading and trailing spaces
if (str.Trim() != strProductID.Trim())
{
strCart += str + ", ";
}
}

// remove the trailing space and comma
if (strCart.Length > 1)
{
strCart = strCart.Trim();
strCart = strCart.Substring(0, strCart.Length - 1);
}

// put it back into Session
Session["Cart"] = strCart;

// rebind the GridView, which will force the SqlDataSource to requery
gvCart.DataBind();

} // close for test for Session


/*
If Session("Cart") IsNot Nothing Then
' remove the selected ProductID from the Session string
' Retrieve the session string.
Dim strCart As String = Session("Cart").ToString()
Dim arIDs As String() = strCart.Split(New [Char]() {","c})

' iterate through the ID's comprising the string array
' rebuild the cart string, leaving out the matching ID
strCart = String.Empty
For Each str As String In arIDs
' use Trim to remove leading and trailing spaces
If str.Trim() <> strProductID.Trim() Then
strCart += str + ", "
End If
Next

' remove the trailing space and comma
If strCart.Length > 1 Then
strCart = strCart.Trim()
strCart = strCart.Substring(0, strCart.Length - 1)
End If

' put it back into Session
Session("Cart") = strCart

' rebind the GridView, which will force the SqlDataSource to requery
gvCart.DataBind()
End If ' close for test for Session
*/
}
این کدو آماده داشتم. توضیحاتشم توش هست. اما بازم توضیح میدم :)
ببینید شما هر انتخابو با یه ویرگول جدا میکنید تو کدو نگاه کنید می بینید. وقتی که انتخابهاتون تموم شد مثلا 5 تا انتخاب کردید حالا اونو باید به sqldatasource بفرستید
sqldatasource یه رویداد داره به اسم selecting خوب اینم کد رویدادش
protected void sqlCart_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{

string strCart = string.Empty;
if (Session["Cart"] != null)
{
strCart = Session["Cart"].ToString();
e.Command.CommandText += " where product.ProductID in (" +
strCart +
") and culture.CultureID = 'en' ";
}
else
{
e.Cancel = true;
}
}
حالا تو زیاد به جدول و ستونهای من توجه نکن تو مال خودتو بذار. در خقیقت تو یه sission داری که به وسیله اون به sqldatasource میگی که دستور whre خودشو با توجه به session آپدیت کنه.
در آخر به این نکته توجه کن که قبلا تو محیط سورس صفخه خودت selectcommadd رو نوشتی و فقط این where که بالا گفتیم بهش اضافه میشه

nassim0
چهارشنبه 28 اردیبهشت 1390, 12:39 عصر
به لطف دوستان مشكل حل شد . از همگي ممنونم