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

كيف اتحكم باظهار الصورة

مغلق
بدأه متعلم طازج في 3 ديسمبر 2005 · 12 رد · 956 مشاهدة · في ASP.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

سلام عليكم ورحمة الله

اخواني الاعزاء اشكركم سلفا وارجوا منكم التكرم بحل هذا المشكلة ان وجد لها حل عندكم

اخواني الاعزاء انا اصمم مشروع تخرج عبارة عن موقع اخباري وواجهتي مشكلة عرض الصور مع النص

حيث اني اذا لم احمل الصورة مع الخبر تظهر لي علامة × داخل المربع ( يعني الصورة مفقدوة )

فكيف اتحكم بالصورة اذا كانت قاعدة البيانات فارعة ( مع العلم اني اخذ اسم الصورة فقط داخل قاعدة البيانات ) ارجوكم ساعدوني

اقصد من كلامي اريد ان لا تظهر الصورة بحال عدم وجودها في قاعدة البيانات :)

وان وجدت في قاعدة البيانات تعرض

#3

اشكرك اخي الكريم

ولكن انا استخدمت في طريقة العرض ربيتر

واستخدمت vb ولم استخدم c#

فارجوا منكم الحل :)

وسوف احول ان اجرب الكود

#4
<asp:Image Visible='<%# Convert.ToString(Container.DataItem("NEWS_IMAGE") ) == "" ? False : True %>' />

هذا الكود داخل الـ Repeater

#5

تسلم اخوي اسماعيل

وما راح انسى لك هذا الجميل

وراح اجرب الكود ومشكور وماقصرت

#6

اخي العزيز

جربت الكود ولكن يوجد خطاء ولذا ارفقت لك الملف وفية الاكواد

<%@ Page Language="VB" debug="true" %>

<%@ Import Namespace=system.data %>

<%@ Import Namespace=system.data.oledb%>

<script runat="server">

Sub Page_Load(Src As Object, E As EventArgs)

dim constar as string = ("provider=microsoft.jet.oledb.4.0; data source= " & server.MapPath("data.mdb") & ";")

dim con as new oledbconnection(constar)

dim ds as new oledbcommand("select * from news where logo = 'a' ", con)

'dim ds as new oledbcommand("select * from news" , con)

con.open()

repnews.DataSource = ds.ExecuteReader

repnews.databind()

con.close()

End Sub

</script>

<html>

<head>

<title>Untitled Document</title>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1256"><form id = f1 runat="server">

<asp:Repeater ID="repnews" runat="server">

<itemtemplate>

<table width="638" border="0">

<tr>

<td colspan="2" rowspan="3"><img src="photonew\<%#Container.DataItem("photo") %>" width =229 height=124 /></td>

<td width="17"> </td>

<td width="393" colspan="3"><%#Container.DataItem("title")%>></td>

</tr>

<tr>

<td> </td>

<td colspan="3" rowspan="4" valign="top"><div align="right">

<blockquote>

<p><%#Container.DataItem("shuort")%></p>

</blockquote>

</div></td>

</tr>

<tr>

<td> </td>

</tr>

<tr>

<td width="131" align="center" valign="baseline"><div align="right"><%#Container.DataItem("dates")%></div></td>

<td width="79"> </td>

<td> </td>

</tr>

<tr>

<td> </td>

<td> </td>

</tr>

</table>

</itemtemplate>

</asp:Repeater>

</form>

</body>

</html>

#7

صلح هذا السطر في الكود

<img src='<%# "photonew/" & Container.DataItem("photo") %>'width =229 height=124 />

تم تعديل هذه المشاركة بواسطة إسماعيل عنجريني في 6 ديسمبر 2005 في 18:38

#8

هلا اخوي العزيز

والله مشكلة الخطاء في الكود نفسة يظهر اذا تكرمت تعدل على الكود :)

الموجود في الاعلى لانة عندي نفس الشي يعني يظهر لي على × الصفحة

او الكود خطاء اذا تكرمت وتعطفت توضح اكثر على الكود نفسة

لانة سويت الشرط

#9
<%@ Page Language="VB" debug="true" %>
<%@ Import Namespace=system.data %>
<%@ Import Namespace=system.data.oledb%>

<script runat="server">


Sub Page_Load(Src As Object, E As EventArgs)

dim constar as string = ("provider=microsoft.jet.oledb.4.0; data source= " & server.MapPath("data.mdb") & ";")

dim con as new oledbconnection(constar)

dim ds as new oledbcommand("select * from news where logo = 'a' ", con)
'dim ds as new oledbcommand("select * from news" , con)


con.open()




repnews.DataSource = ds.ExecuteReader

repnews.databind()

con.close()

End Sub




</script>




<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256"><form id = f1 runat="server">
<asp:Repeater ID="repnews" runat="server">
<itemtemplate>
<table width="638" border="0">
<tr>

<td colspan="2" rowspan="3">

<asp:Image ImageUrl='<%# "photonew/" & Container.DataItem("photo") %>' Visible='<%# Convert.ToString(Container.DataItem("photo") ) == "" ? False : True %>' width =229 height=124 />

</td>
<td width="17"> </td>
<td width="393" colspan="3"><%#Container.DataItem("title")%>></td>

</tr>
<tr>
<td> </td>
<td colspan="3" rowspan="4" valign="top"><div align="right">
<blockquote>
<p><%#Container.DataItem("shuort")%></p>
</blockquote>
</div></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td width="131" align="center" valign="baseline"><div align="right"><%#Container.DataItem("dates")%></div></td>
<td width="79"> </td>
<td> </td>
</tr>
<tr>

<td> </td>
<td> </td>
</tr>
</table>
</itemtemplate>
</asp:Repeater>

</form>



</body>
</html>
#10

تسلم اخي العزيز

ولكن تركيب الجملة خاطى لانك تستخدم c# وانا استخدم في بي

ولذا لا يعمل :)

#11
Private Sub Repeater1_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemCreated
        Dim img As System.Web.UI.WebControls.Image = CType(e.Item.FindControl("NewsImage"), System.Web.UI.WebControls.Image)
        If Not img Is Nothing Then
            If img.ImageUrl = "" Then
                img.Visible = False
            End If
        End If
    End Sub

طبعاً بفرض صورة الخبر اسمها NewsImage

#12

اشكر ك اخي اسماعيل واعذرني على الازعاج ولكن لا حياء في العلم هكذا تعلمنا واعذرني مرة اخرى

<%@ Page Language="VB" debug="true" %>
<%@ Import Namespace=system.data %>
<%@ Import Namespace=system.data.oledb%>

<script runat="server">


Sub Page_Load(Src As Object, E As EventArgs)

dim constar as string = ("provider=microsoft.jet.oledb.4.0; data source= " & server.MapPath("data.mdb") & ";")

dim con as new oledbconnection(constar)

dim ds as new oledbcommand("select * from news where logo = 'a' ", con)
'dim ds as new oledbcommand("select * from news" , con)


con.open()




repnews.DataSource = ds.ExecuteReader

repnews.databind()

con.close()

End Sub



Private Sub imgshow(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) 
       Dim img As System.Web.UI.WebControls.Image = CType(e.Item.FindControl("photos"), System.Web.UI.WebControls.Image)
       If Not img Is Nothing Then
           If img.ImageUrl = "" Then
               img.Visible = False
           End If
       End If
   End Sub




</script>




<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256"><form id = f1 runat="server">
<asp:Repeater ID="repnews" runat="server"  onItemCreated=imgshow  >
<itemtemplate>
<table width="638" border="0">
<tr>

<td colspan="2" rowspan="3">

<asp:Image ImageUrl='<%# "photonew/" & Container.DataItem("photo") %>' id = photos width =229 height=124 />

</td>
<td width="17"> </td>
<td width="393" colspan="3"><%#Container.DataItem("title")%>></td>

</tr>
<tr>
<td> </td>
<td colspan="3" rowspan="4" valign="top"><div align="right">
<blockquote>
<p><%#Container.DataItem("shuort")%></p>
</blockquote>
</div></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td width="131" align="center" valign="baseline"><div align="right"><%#Container.DataItem("dates")%></div></td>
<td width="79"> </td>
<td> </td>
</tr>
<tr>

<td> </td>
<td> </td>
</tr>
</table>
</itemtemplate>
</asp:Repeater>

</form>



</body>
</html>

اخي العزيز هذا هو الكود وهو معدل ولكن ( اما ان يظهر الكل او يخفي الكل :) ما عندة شي وسط

اخي العزيز طلب لو تكرتم تسوية وترفق الملف :)

او تعدل على ما سويت

صحيح انها رزالة :) ولكن في التعلم مافي حياء او عيب :)

واعتذر منك

#13

سلام شباب لقد حصلت على كود وبطريقة اخرى واشكر كل من سعادني وسوف اضعة لكم لكي نتعلم جميعا من اخطانا

public Sub imgshow(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) 
Dim img As System.Web.UI.WebControls.Image = CType(e.Item.FindControl("img"), System.Web.UI.WebControls.Image)

if trim(CType(e.Item.FindControl("checkimag"), System.Web.UI.WebControls.textbox).text)="" then

img.Visible = False
End If

وتضع في Repeater

text box ونجعل حالة مخفي انا جعلته هنا ظهار من باب التجربة

<asp:Repeater ID="repnews" runat="server"  >
<itemtemplate>
<div>
<%#Container.DataItem("dates")%>
<a href="Copy.aspx?fieldc=news&id=<%#Container.DataItem("id")%>"><%#Container.DataItem("tilel")%> 

</div>
<asp:Image ImageUrl='<%# "photonew" & Container.DataItem("photo") %>' runat="server" ID="img" />

<asp:TextBox ID="checkimag" Text='<%# Container.DataItem("photo") %>' runat="server" ></asp:TextBox>
</itemtemplate>
</asp:Repeater>

طبعا هنا الاسماء هي خاصة بقاعدتي ولكن تغيرها وفي

<asp:Repeater ID="repnews" runat="server" >

نضيف لة اسم الفنكشن ليصبح هكذا

<asp:Repeater ID="repnews" runat="server" OnItemDataBound="imgshow" >

تم تعديل هذه المشاركة بواسطة متعلم طازج في 15 ديسمبر 2005 في 18:17

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

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