الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مشكله بال GridView update ولكن ل Template field

مغلق
بدأه صلاح الثبيتي في 21 مايو 2006 · 2 رد · 734 مشاهدة · في ASP.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم :)

عندي مشكله صغيره،،

صممت GridView وابغى اسوي update لعمود واحد فقط لكل صف!

كتبت هذا الكود ولكن عند عمليه التحديث، لايتم حفظ المعلومات بقاعدة البيانات

الكود: (الهدف من الكود هو التحكم بكيفيه عرض البيانات عند استخدام Edit وكيفيه حفظها بقاعدة البيانات)

=====

بعد التصحيح

=====

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
	CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" DataKeyNames="ownerId">
	<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
	<Columns>
		<asp:TemplateField>
			<EditItemTemplate>
				<asp:Label ID="Label2" runat="server" Text='<%# Bind("ownerId") %>'></asp:Label>
			</EditItemTemplate>
			<ItemTemplate>
				<asp:Label ID="Label1" runat="server" Text='<%# Eval("ownerId") %>'></asp:Label>
			</ItemTemplate>
			<HeaderTemplate>
				<asp:Label ID="ownerId" runat="server" Text="ownerId"></asp:Label>
			</HeaderTemplate>
		</asp:TemplateField>
		<asp:TemplateField>
			<EditItemTemplate>
				<asp:Label ID="Label4" runat="server" Text='<%# Eval("ownerEnName") %>'></asp:Label>
			</EditItemTemplate>
			<ItemTemplate>
				<asp:Label ID="Label3" runat="server" Text='<%# Eval("ownerEnName") %>'></asp:Label>
			</ItemTemplate>
			<HeaderTemplate>
				<asp:Label ID="ownerEnName" runat="server" Text="ownerEnName"></asp:Label>
			</HeaderTemplate>
		</asp:TemplateField>
		<asp:TemplateField>
			<EditItemTemplate>
				<asp:TextBox ID="Label6" runat="server" Text='<%# Bind("ownerArName") %>'></asp:TextBox>
			</EditItemTemplate>
			<ItemTemplate>
				<asp:Label ID="Label5" runat="server" Text='<%# Eval("ownerArName") %>'></asp:Label>
			</ItemTemplate>
			<HeaderTemplate>
				<asp:Label ID="ownerArName" runat="server" Text="ownerArName"></asp:Label>
			</HeaderTemplate>
		</asp:TemplateField>
		<asp:CommandField ShowEditButton="True" ButtonType="Button" />
	</Columns>
	<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
	<EditRowStyle BackColor="#999999" />
	<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
	<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
	<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
	<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:connectionString %>"
	SelectCommand="A" SelectCommandType="StoredProcedure" UpdateCommand="B" UpdateCommandType="StoredProcedure">
	<SelectParameters>
		<asp:ControlParameter ControlID="txtVendorId" Name="vendorId" PropertyName="Text" Type="Int32" />
	</SelectParameters>
	<UpdateParameters>
		<asp:Parameter Name="ownerId" Type="Int32" />
		<asp:Parameter Name="ownerArName" Type="String" />
	</UpdateParameters>
</asp:SqlDataSource>

استخدم Bind عند العرض والحذف والتعديل

واستخدام Eval للعرض فقط

(واذا شخص يحب يزيد شويه معلومات،، فله كامل التصرف :D)

#2

شغلك تمام بس ناقصك شي بسيط في Tags ال Update

<UpdateParameters>
		<asp:ControlParameter  ControlID="Label2" PropertyName="Text" Name="ownerId" Type="Int32" ControlId />
		<asp:ControlParameter  ControlID="Label6" PropertyName="Text" Name="ownerArName" Type="String" />
	</UpdateParameters>

بالتوفيق

logo.gif
استضافة ويندوز


اقتباس

مساحة تبدأ من 2000 ميجا بايت بسعر 1.99 دولار شهريا.ا

اقتباس

ASP.NET 1.1-2.0-3.0-3.5-4.0-4.5.1 / MVC ASP.NET / PHP 5.x / ColdFusion / MSSQL 2008 & 2012 / MYSQL

هذا الموضوع مغلق.

مواضيع مشابهة