472,805 Members | 820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

HELP! Listview not working with edit button ASP.NET

4
Posted this on Asp.Net, seems to be a hard problem, I still can't work it out

I have a edit button, this works fine, until I add the code that prevents the edit button from being seen by users who did not post that ticket. I cannot understand why this is happening. I get an error on the button says 'object reference not set in instance of object'



It happens when I add the following code:


Expand|Select|Wrap|Line Numbers
  1. protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
  2.     {
  3.         HiddenField commentidfield = e.Item.FindControl("commentidfield") as HiddenField;
  4.         HiddenField userloginfield = e.Item.FindControl("userloginfield") as HiddenField;
  5.  
  6.         ImageButton votebutton = e.Item.FindControl("commentvotebutton") as ImageButton;
  7.         ImageButton editbutton = e.Item.FindControl("editbutton") as ImageButton;
  8.  
  9.  
  10.  
  11.         if (HttpContext.Current.User.Identity.IsAuthenticated == true)
  12.         {
  13.             int commentidtemp = Convert.ToInt32(commentidfield.Value);
  14.             int userloginid = Convert.ToInt32(userloginfield.Value);
  15.  
  16.             int commentcheck = Convert.ToInt32(commentratingclass.CheckCommentVote(Profile.userid, commentidtemp).GetValueOrDefault(0));
  17.             int editcheck = Convert.ToInt32(commentclass.checkcommentbyuserid(Profile.userid, commentidtemp).GetValueOrDefault(0));
  18.  
  19.  
  20.             if (userloginid == Profile.userid)
  21.             {
  22.                 votebutton.Visible = false;
  23.             }
  24.             else if (commentcheck > 0)
  25.             {
  26.                 votebutton.ImageUrl = "Images/commentvoted.png";
  27.                 votebutton.Enabled = false;
  28.             }
  29.             else
  30.             {
  31.                 votebutton.ImageUrl = "Images/commentvote.png";
  32.                 votebutton.Enabled = true;
  33.             }
  34.  
  35.             if (editcheck == 0)
  36.             {
  37.                 editbutton.Visible = false;
  38.             }
  39.             else
  40.             {
  41.                 editbutton.Visible = true;
  42.             }
  43.         }
  44.         else
  45.         {
  46.             votebutton.Visible = false;
  47.             editbutton.Visible = false;
  48.         }
  49.  
  50.  
  51.     }
  52.  
  53.  
  54.  
Listview:

Expand|Select|Wrap|Line Numbers
  1.  
  2. 1    <asp:ListView ID="ListView1" runat="server" DataKeyNames="CommentID" DataSourceID="SqlDataSource1"
  3. 2                    OnItemDataBound="ListView1_ItemDataBound" 
  4. 3                    onitemupdating="ListView1_ItemUpdating">
  5. 4                    <LayoutTemplate>
  6. 5                        <table runat="server">
  7. 6                            <tr runat="server">
  8. 7                                <td runat="server">
  9. 8                                    <table id="itemPlaceholderContainer" runat="server" border="0" style="">
  10. 9                                        <tr id="itemPlaceholder" runat="server">
  11. 10                                       </tr>
  12. 11                                   </table>
  13. 12                               </td>
  14. 13                           </tr>
  15. 14                           <tr runat="server">
  16. 15                               <td runat="server" style="">
  17. 16                                   <center>
  18. 17                                       <asp:DataPager ID="DataPager1" runat="server">
  19. 18                                           <Fields>
  20. 19                                               <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowNextPageButton="False"
  21. 20                                                   ShowPreviousPageButton="False" />
  22. 21                                               <asp:NumericPagerField />
  23. 22                                               <asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True" ShowNextPageButton="False"
  24. 23                                                   ShowPreviousPageButton="False" />
  25. 24                                           </Fields>
  26. 25                                       </asp:DataPager>
  27. 26                                   </center>
  28. 27                               </td>
  29. 28                           </tr>
  30. 29                       </table>
  31. 30                   </LayoutTemplate>
  32. 31                   <EmptyDataTemplate>
  33. 32                       <table runat="server" style="">
  34. 33                           <tr>
  35. 34                               <td>
  36. 35                                   No Answers! Add one Now!
  37. 36                               </td>
  38. 37                           </tr>
  39. 38                       </table>
  40. 39                   </EmptyDataTemplate>
  41. 40                   <EditItemTemplate>
  42. 41                    <table class="comments">
  43. 42                           <tr>
  44. 43                               <td class="commentsheader" rowspan="2">
  45. 44                                   <asp:Label ID="UserIDLabel" runat="server" Text='<%# Eval("Login") %>' />
  46. 45                                   answered:
  47. 46                                   <div id="details">
  48. 47                                       <br />
  49. 48                                       Rating:
  50. 49                                       <asp:Label ID="Usersratinglabel" runat="server" Text='<%#  Eval("Rating") %>' />
  51. 50                                       <br />
  52. 51                                       Posts:
  53. 52                                         <asp:Label ID="Usersanswers" runat="server" Text='<%#  Eval("Answers") %>' />
  54. 53                                       <asp:HiddenField ID="commentidfield" runat="server" Value='<%# Eval("CommentID") %>' />
  55. 54                                       <asp:HiddenField ID="userloginfield" runat="server" Value='<%# Eval("UserID") %>' />
  56. 55                               </td>
  57. 56                               <td class="commentsmain">
  58. 57                                   <asp:TextBox ID="updatetext" runat="server" Text='<%# Bind("Comment") %>' TextMode="MultiLine"
  59. 58                                       Width="500px" Height="150px" />
  60. 59                               </td>
  61. 60                           </tr>
  62. 61                           <tr>
  63. 62                               <td class="commentfooter">
  64. 63                                   <div class="commentfooter">
  65. 64                                       <asp:Button ID="updatebutton" runat="server" Text="Update"  CommandName="Update" />
  66. 65                                       <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
  67. 66                               </td>
  68. 67                           </tr>
  69. 68                           </td> </tr>
  70. 69                       </table>
  71. 70                   </EditItemTemplate>
  72. 71                   <ItemTemplate>
  73. 72                       <table class="comments">
  74. 73                           <tr>
  75. 74                               <td class="commentsheader" rowspan="2">
  76. 75                                   <asp:Label ID="UserIDLabel" runat="server" Text='<%# Eval("Login") %>' />
  77. 76                                   answered:
  78. 77                                   <div id="details">
  79. 78                                       <br />
  80. 79                                       Rating:
  81. 80                                       <asp:Label ID="Usersratinglabel" runat="server" Text='<%#  Eval("Rating") %>' />
  82. 81                                       <br />
  83. 82                                       Posts:
  84. 83                                       <asp:Label ID="Usersanswers" runat="server" Text='<%#  Eval("Answers") %>' />
  85. 84                                       <asp:HiddenField ID="commentidfield" runat="server" Value='<%# Eval("CommentID") %>' />
  86. 85                                       <asp:HiddenField ID="userloginfield" runat="server" Value='<%# Eval("UserID") %>' />
  87. 86                               </td>
  88. 87                               <td class="commentsmain">
  89. 88                                   <asp:Label ID="CommentLabel" runat="server" Text='<%# Eval("Comment") %>' />
  90. 89                               </td>
  91. 90                           </tr>
  92. 91                           <tr>
  93. 92                               <td class="commentfooter">
  94. 93                                   <asp:ImageButton ID="editbutton" CommandName="Edit" runat="server" ImageUrl="Images/commentedit.png" />
  95. 94                                   <asp:ImageButton ID="commentvotebutton" runat="server" OnCommand="commentvote_Click" ImageUrl="Images/commentvote.png"
  96. 95                                       CommandArgument='<%# Eval("CommentID") %>' CommandName="commentvote" />
  97. 96                               </td>
  98. 97                           </tr>
  99. 98                           </td> </tr>
  100. 99                       </table>
  101. 100                  </ItemTemplate>
  102. 101              </asp:ListView>
  103.  
  104.  
  105.  
Mar 20 '08 #1
0 2321

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
4
by: Sarir Khamsi | last post by:
Is there a way to get help the way you get it from the Python interpreter (eg, 'help(dir)' gives help on the 'dir' command) in the module cmd.Cmd? I know how to add commands and help text to...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
6
by: d.warnermurray | last post by:
I am doing a project for school that involves creating help files for a html authoring tool. If you could help me with answers to some questions it would really help. 1. What tasks do you expect...
0
by: tbatwork828 | last post by:
If you were like me trying to figure out how to launch context sensitive help topic by the context id, here is the link: http://weblogs.asp.net/kencox/archive/2004/09/12/228349.aspx and if...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
5
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
1
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.