با سلام و عرض خسته نباشید خدمت کلیه عزیزان و برنامه نویسان
بنده در کد نویسی به مشکلی برخورده ام که به شرح زیر می باشد :
هنگامی که پیج grid view را عوض میکنم اطلاعات data key خوانده نمی شود و این اررور را میدهد . لازم به ذکر است grid view بنده در update panel قرار دارد
HTML :
<asp:ScriptManager ID="ScriptManager1" runat="server" ></asp:ScriptManager> <asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server"></asp:ScriptManagerProxy> <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Always" > <ContentTemplate> <!--Messeage box!--> <div id="DivMesseage" runat="server"></div> <!--main content start--> <section id="main-content"> <section class="wrapper"> <!-- page start--> <div class="row"> <div class="col-lg-12"> <section class="panel"> <header class="panel-heading">محصولات سایت </header> <style> .textAlignCenter {text-align:center;} .HeaderGv {} .HeaderGv th{ text-align:center} .PagetGvProduct { border:1px solid WhiteSmoke; } .PagetGvProduct table { } .PagetGvProduct table tr{ } .PagetGvProduct table tr td { border: 1px solid #e4e4e4; color: #797979; margin: 2px; border-radius: 5px; padding: 5px 10px; display: inline-block; } </style> <asp:GridView ID="gvProducts" runat="server" EnablePaging="true" PageSize="5" AllowPaging="true" AllowSorting="true" CssClass="table table-hover table-striped table-advance textAlignCenter" OnRowCommand="gvProducts_RowCommand" OnPageIndexChanging="gvProducts_PageIndexChanging" OnPageIndexChanged="gvProducts_PageIndexChanged" AutoGenerateColumns="false" OnPreRender="gvProducts_PreRender" BorderStyle="None" RowStyle-BorderColor="White" HeaderStyle-BorderColor="WhiteSmoke" HeaderStyle-CssClass="HeaderGv" DataKeyNames="ProductCode" > <PagerSettings PageButtonCount="5" /> <PagerStyle CssClass="PagetGvProduct" /> <Columns> <asp:BoundField HeaderText="#" DataField="RowIndex_ProductCode" /> <asp:BoundField HeaderText="نام محصول" DataField="ProductName" /> <asp:BoundField HeaderText="تاریخ ثبت (شمسی)" DataField="RegPersianDate" /> <asp:BoundField HeaderText=" تاریخ ثبت (میلادی)" DataField="RegDate"/> <asp:BoundField HeaderText=" وضعیت محصول" DataField="ProductStatus"/> <asp:BoundField HeaderText="کد محصول" DataField="ProductCode"/> <asp:TemplateField> <ItemTemplate> <asp:Button ID="BtnEdit" runat="server" Text="ویرایش" CssClass="btn btn-primary btn-xs" CommandName="btnEdit" CommandArgument='<%#Eval("RowIndex_ProductCode") %>'/> <asp:Button ID="BtnDelete" runat="server" Text="x" CssClass="btn btn-danger btn-xs" CommandName="BtnDelete" CommandArgument='<%#Eval("RowIndex_ProductCode") %>' OnClientClick="return confirm('آیا از حذف محصول خود مطمئن هستید؟')" /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </section> </div> </div> <!-- page end--> </section> </section> </ContentTemplate> </asp:UpdatePanel>
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //_beforeClick(); GetProducts(); } } private void GetProducts() { try { //_beforeclick(); DivMesseage.InnerHtml = String.Empty; DataSet ds = new DataSet(); AppCode.SQLConnection SQL = new AppCode.SQLConnection(); NameValueCollection nameVC = new NameValueCollection(); nameVC.Add("@U_ID", "3"); //AppCode.EncryptDecrypt._Decrypt(HttpContext.Current.Session["SessionSysUserId"].ToString()) AppCode.SQLConnection._DBReaderWithDataSetWithStoreProcedure("sp_Products_GetProductsListForAdminPanel", nameVC, ref ds); if (ds.Tables.Count == 0 || ds.Tables.Count < 0) { DivMesseage.InnerHtml = AppCode.Functions._ShowMessage(" توجه " , " هیچ اطلاعاتی یافت نشد "); RunMesseageBox(); return; } else { if (ds.Tables[0].Rows.Count > 0) { gvProducts.DataSource = ds.Tables[0]; gvProducts.DataBind(); } else { gvProducts.DataSource = ds.Tables[""]; gvProducts.DataBind(); // Divmsg.InnerHtml = AppCode.Function._ShowMessage("توجه", AppCode.Message._DivWarning("هیچ اطلاعاتی یافت نشد")); return; } } } catch (Exception ex) { } } protected void gvProducts_PreRender(object sender, EventArgs e) { if (gvProducts.Rows.Count > 0) { gvProducts.UseAccessibleHeader = true; gvProducts.HeaderRow.TableSection = TableRowSection.TableHeader; } } protected void gvProducts_PageIndexChanging(object sender, GridViewPageEventArgs e) { try { gvProducts.PageIndex = e.NewPageIndex; GetProducts(); } catch (Exception ex) { //msg.InnerHtml = ""; msg.InnerHtml = AppCode.Function._ShowMessage("خطا 003", "خطا در انجام عملیات"); return; } } protected void gvProducts_RowCommand(object sender, GridViewCommandEventArgs e) { try { if (e.CommandName.Equals("BtnDelete")) { DivMesseage.InnerHtml = String.Empty; String Row_Index = e.CommandArgument.ToString(); Int32 RowIndex = 0; RowIndex = Int32.Parse(Row_Index); RowIndex = RowIndex - 1; String ProductCode = gvProducts.DataKeys[RowIndex]["ProductCode"].ToString(); AppCode.SQLConnection SQL = new AppCode.SQLConnection(); NameValueCollection NVC = new NameValueCollection(); NVC.Add("@UID", "3"); //AppCode.EncryptDecrypt._Decrypt(HttpContext.Current.Session["SessionSysUserId"].ToString()) NVC.Add("@ProductCode", ProductCode); SqlParameter[] sqlParam = { }; if (AppCode.SQLConnection._Execute2DBWithStoreProcedure("[sp_Products_DeleteProductsByProductCode]", NVC, ref sqlParam)) { GetProducts(); } //Session["Row_IDSuggestion"] = Row_ID; //if (Session["Row_IDSuggestion"] == null || String.IsNullOrEmpty(Session["Row_IDSuggestion"].ToString())) // return; //msg.InnerHtml = AppCode.Function._ShowInnerPage("انتقاد / پیشنهاد", ResolveClientUrl("~/fa/Admin/SuggestionDetail.aspx")); //return; } /*else if (e.CommandName == "BtnDelete") { String Row_Index = e.CommandArgument.ToString(); String Row_ID = GridView_SentSuggestions.DataKeys[Int32.Parse(Row_Index) - 1]["Row_ID"].ToString(); SqlParameter[] n = { }; NameValueCollection NVCD = new NameValueCollection(); NVCD.Add("@IdentyToWork", "5"); NVCD.Add("@UserID", AppCode.EncryptDecrypt._Decrypt(HttpContext.Current.Session["SessionSysUserId"].ToString())); NVCD.Add("@IdeaID", Row_ID); AppCode.Connect2DB._Execute2DBWithStoreProcedure("[sp_IPC_GetSuggestion]", NVCD, ref n); ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('پیشنهاد مورد نظر شما حذف شد')", true); msg.InnerHtml = ""; GetSent_Suggestions(); }*/ } catch (Exception) { //msg.InnerHtml = ""; msg.InnerHtml = AppCode.Function._ShowMessage("خطا 002", "خطا در انجام عملیات"); return; } } protected void gvProducts_PageIndexChanged(object sender, EventArgs e) { GetProducts(); }
سوال بنده رو پاسخ بدید کمال تشکر رو دارم
این لینک رو ببینید
این لینکی که شما زحمت کشیدید رو دیده بودم
مشکل من line 86 کدمه که نمیتونه product code رو ارسال کنه
اگه کسی به این تاپیک پاسخ بده ممنونش میشم
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)