data grid

orengolan

New member
../images/Emo147.gifdata grid

שלום, אני בונה אפליקצית WEB FORM. יש לי DATA GRID, ואחת מהעמודות שלו היא IMAGEBUTTON (עמודה TEMPLATE). בעמודה אחרת ישנם נתונים BOOLIENS-TRUE OR FALSE שנקראים מבסיס הנתונים. ברצוני לבצע את הדבר הבא: עם ה-LOAD של ה-DATAGRID, להעלים (VISIBLE=FALSE) את ה-IMAGEBUTTON בשורות שבהם המשתנה הבוליאני המתאים (באותה שורה) שווה ל-FALSE. כיצד ניתן לעשות זאת? לגשת ל-IMAGEBUTTON אין לי בעיה, הבעיה היא לקרוא את הנתונים הבוליאנים בעת ה-LOAD.
 

yuval k

New member
אתה יכול לעשות if על ערך מהטבלה, כך

<itemtemplate> <%# (DataBinder.Eval(Container.DataItem, "booleanField") ? "button" : "" %> </itemtemplate>​
למשל... ואז הוא לא ייכתב למסמך בכלל (כמו כשהוא visible=false). אתה גם יכול לתפוס את אירוע DataItemBound, כדי לתת ערך false למאפיין הזה (בדומה למה שמופיע פה).
 

orengolan

New member
לא עובד

hi yuval, first of all thanks 4 your answer. i tried your first suggestion and i got a compilation error: "Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: BC30037: Character is not valid." the error is occured during the load for the line you gave me: <ItemTemplate> <asp:ImageButton id="ImgBttnSale" runat="server" CommandName="Sale" ImageUrl='<%#DataBinder.Eval(Container.DataItem, "sale") ? "ImageButton" : "" %>' Visible="False"></asp:ImageButton> </ItemTemplate> as well, i tried "DataItem.sale" instead of "sale" ("sale" is the name of the boolien field). where is my mistake? does the ? "ImageButton" : "" should work the visibility part? i tried "Button" instead of "ImageButton" as well, same error. thanks. oren
 

yuval k

New member
אנא יישר את ההודעה לשמאל...

הפתרון הראשון לא היה טוב
לא משנה. בכל אופן, אתה צריך משהו כזה -
void DataGrid1_ItemDataBound(object Sender, DataGridItemEventArgs e) { ImageButton imgButton = (ImageButton)e.Item.FindControl("ImgBttnSale"); imgButton.Visible = (DataBinder.Eval(e.Item.DataItem, "sale") == "true"); }​
כמטפל האירוע ItemDataBound.
 

orengolan

New member
גם זה לא עובד

This code is not working as well. The error now: Operator is not valid for type 'DBNull' and type 'Integer'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Operator is not valid for type 'DBNull' and type 'Integer'. in the debugger i can notice that the value of: DataBinder.Eval(e.Item.DataItem, "sale") is: {System.DBNull} what can b done? p.s when writing this messege i do c it from left 2 right. only when uploading, it becomes from right 2 left. sorry.
 

yuval k

New member
יישר את ההודעה ע"י |הקוד| ו|סקוד|

יש ערך בשדה של sale?
 

OnTheRoad

New member
תפעיל פונקציה על הערך

שתבדוק מהו הערך ולפי זה תבצע פלט
 

orengolan

New member
עוד שאלה

אם אני מחליט לעשות את זה ע"י DATAITEMBOUND, מה אני עושה במקום "ONCLICK"? איך אני מקשר לו את ה-VISIBILITY לפי שדה מהבסיס נתונים \ מה-DATAGRID? תודה
 

nattygur

New member
אתה יכול

להשתמש בארוע ItemCreated של הגריד בכדי לטפל בתוכן העמודות לפי תוכן של עמודות אחרות.
 
למעלה