PDA

View Full Version : enable selection توی گریدویو در ستون template



bahar_engineer
شنبه 30 آبان 1388, 12:25 عصر
سلام

شاید خیلی ابتدایی به نظر بیاد اما می خوام گریدویو قابلیت select داشته باشه و بتونم اونو هرجایی که می خوام بذارم یعنی مثل template اما نتونستم توی template پیاده سازیش کنم

یه عکس گذاشتم و commandname شو select گذاشتم و در selectedindexchange دستوراتم رو نوشتم اما خطا داد .... خطایی طولانی راجع به postback و...

چطور می تونم این کار و بکنم؟
اگه لازمه کدها رو بذارم اما هیچ ارتباطی به موضوع ندارن یعنی اگه به حالت عادی در گریدویو enable select رو تیک بزنم و اونوقت توی selectedindexchanged دستوراتو بنویسیم هیچ مشکلی نیست

alireza_s_84
شنبه 30 آبان 1388, 12:37 عصر
سلام

شاید خیلی ابتدایی به نظر بیاد اما می خوام گریدویو قابلیت select داشته باشه و بتونم اونو هرجایی که می خوام بذارم یعنی مثل template اما نتونستم توی template پیاده سازیش کنم

یه عکس گذاشتم و commandname شو select گذاشتم و در selectedindexchange دستوراتم رو نوشتم اما خطا داد .... خطایی طولانی راجع به postback و...

چطور می تونم این کار و بکنم؟
اگه لازمه کدها رو بذارم اما هیچ ارتباطی به موضوع ندارن یعنی اگه به حالت عادی در گریدویو enable select رو تیک بزنم و اونوقت توی selectedindexchanged دستوراتو بنویسیم هیچ مشکلی نیست
سلام:
فکر کنم خطای معروف Invalid PostBack Or CallBack Variable باشه.
کدهاتون رو بذارید تا دقیق بگم کجاش ایراد دارید.

bahar_engineer
شنبه 30 آبان 1388, 12:57 عصر
سورس صفحه :


<%@ Page Language="C#‎" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="product_details.aspx.cs" Inherits="product_details" Title="معرفی محصول"%>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table border="0" cellpadding="0" cellspacing="0" style="width: 540px; position: static;
height: 28px; background-color: #ffffff;">
<tr>
<td style="width: 118px; height: 31px">
</td>
<td style="background-image: url(picture/topbigmenu.png); width: 19147px; height: 31px;
text-align: right">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
</td>
</tr>
<tr>
<td style="width: 118px" valign="top">
</td>
<td align="right" style="width: 19147px" valign="top">
<div style="text-align: center">
<div style="text-align: right">
<table style="width: 535px; height: 18px">
<tr>
<td style="width: 100px">
</td>
<td style="width: 100px">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
BackColor="White" CaptionAlign="Top" ForeColor="#404040"
GridLines="None" Height="1px" PageSize="1" Style="background-color: transparent"
Width="366px" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<PagerSettings Visible="False" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<div style="text-align: right">
<table dir="rtl" style="width: 397px; direction: rtl; position: static; text-align: right">
<tr>
<td style="width: 549px; direction: rtl; height: 16px; text-align: right">
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Names="Tahoma" Font-Size="Small"
ForeColor="#4884D8" Style="font-size: 8pt; color: #59c0eb" Text='<%# Eval("ProductName") %>'></asp:Label></td>
</tr>
<tr>
<td style="width: 549px; height: 16px; text-align: left; font-size: 1pt;">
<div style="text-align: left">
<table style="width: 485px; position: static">
<tr>
<td style="border-top: darkgray 1px solid; width: 315px; direction: rtl; height: 7px;
text-align: right" valign="top">
<div style="text-align: right">
<table style="font-size: 8pt; width: 269px; color: #59c0eb; direction: rtl; font-family: tahoma;
text-align: right">
<tr>
<td style="width: 286px">
گروه<span style="font-size: 15pt; color: #59c0eb; font-family: Times New Roman">☺<asp:Label
ID="Label3" runat="server" Font-Bold="False" Font-Names="Tahoma" Font-Size="Small"
ForeColor="Gainsboro" Style="font-size: 8pt; color: #424242" Text='<%# Eval("groups") %>'></asp:Label>☺<asp:Label
ID="Label6" runat="server" Font-Bold="False" Font-Names="Tahoma" Font-Size="Small"
ForeColor="Gainsboro" Style="font-size: 8pt; color: #424242" Text='<%# Eval("sub") %>'></asp:Label></span></td>
</tr>
<tr style="font-size: 8pt">
<td style="width: 286px">
<span style="font-size: 8pt">
تاریخ ارسال :
<asp:Label ID="Label4" runat="server" Font-Bold="False" Font-Names="Tahoma" Font-Size="X-Small"
ForeColor="Gainsboro" Style="font-size: 8pt; color: #424242; direction: ltr;
font-family: tahoma; text-align: right" Text='<%# Eval("dat") %>'></asp:Label></span></td>
</tr>
<tr style="font-size: 8pt">
<td style="width: 286px">
قیمت :
<asp:Label ID="Label7" runat="server" Font-Bold="False" Font-Names="Tahoma" Font-Size="X-Small"
ForeColor="Gainsboro" Style="font-size: 8pt; color: #424242; direction: ltr;
font-family: tahoma; text-align: right" Text='<%# Eval("UnitPrice") %>'></asp:Label></td>
</tr>
<tr style="font-size: 8pt">
<td style="width: 286px">
فروشنده :
<asp:Label ID="Label8" runat="server" Font-Bold="False" Font-Names="Tahoma" Font-Size="X-Small"
ForeColor="Gainsboro" Style="font-size: 8pt; color: #424242; direction: ltr;
font-family: tahoma; text-align: right" Text='<%# Eval("company") %>'></asp:Label></td>
</tr>
<tr style="font-size: 8pt">
<td style="width: 286px">
تعداد محصول موجود در انبار :
<asp:Label ID="Label9" runat="server" Font-Bold="False" Font-Names="Tahoma" Font-Size="X-Small"
ForeColor="Gainsboro" Style="font-size: 8pt; color: #424242; direction: ltr;
font-family: tahoma; text-align: right" Text='<%# Eval("available") %>'></asp:Label></td>
</tr>
<tr style="font-size: 8pt">
<td style="width: 286px">
<asp:Label ID="Label5" runat="server" Font-Names="Tahoma" Font-Size="Small" ForeColor="White"
Height="100px" Style="font-size: 8pt; vertical-align: top; overflow: hidden;
width: 260px; color: #424242; direction: rtl; position: static; text-align: right"
Text='<%# Eval("summerize") %>' Width="468px"></asp:Label></td>
</tr>
</table>
</div>
</td>
<td style="width: 100px; height: 7px">
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("pic") %>' Width="200px" /></td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td dir="rtl" style="width: 549px" valign="top">
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/picture/buy.png"
ToolTip="اضافه به سبد خرید" CommandName="Select" /></td>
</tr>
<tr>
<td dir="rtl" style="width: 549px" valign="top">
<asp:Label ID="Label2" runat="server" Font-Names="Tahoma" Font-Size="Small" ForeColor="White"
Style="color: #424242" Text='<%# Eval("details") %>'></asp:Label></td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
&nbsp; &nbsp;
</td>
<td style="width: 100px">
</td>
</tr>
</table>
</div>
</div>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
</td>
</tr>
</table>
</asp:Content>


CodeBehind:


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

public partial class product_details : System.Web.UI.Page
{
DataSet ds = new DataSet();

protected void Page_Load(object sender, EventArgs e)
{
string m;
m = Request["id"];

string c = "provider=microsoft.jet.oledb.4.0;data source=" + Server.MapPath("shop.mdb");
OleDbConnection con = new OleDbConnection(c);

OleDbDataAdapter ad = new OleDbDataAdapter("Select * from MyProducts where ProductID=" + m, con);
ad.Fill(ds, "MyProducts");
GridView1.DataSource = ds;
GridView1.DataMember = "MyProducts";
GridView1.DataBind();

string k;
k = "select * from MyProducts where ProductID =" + m;
OleDbCommand cmd = new OleDbCommand(k, con);
OleDbDataReader dr;
con.Open();
dr = cmd.ExecuteReader();
dr.Read();
Page.Header.Title = dr["ProductName"].ToString();
con.Close();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
int ProdID = int.Parse(ds.Tables["MyProducts"].Rows[GridView1.SelectedIndex]["ProductID"].ToString());
ShoppungCart.GetShoppingCart().AddItem(ProdID);
Response.Redirect("ViewCart.aspx");
}
}

توی سورس صفحه EnableEventValidation رو false کردم اما دیگه اصلا select انجام نمی شه

bahar_engineer
شنبه 30 آبان 1388, 16:10 عصر
وقتی برای صفحه !ispostback! می ذارم خطای object not refrence to an instance

برای این خط :


int ProdID = int.Parse(ds.Tables["MyProducts"].Rows[GridView1.SelectedIndex]["ProductID"].ToString());


این خطا نمی خواد دست از سر من برداره.