473,888 Members | 1,376 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HELP! Listview not working with edit button ASP.NET

4 New Member
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 2385

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

Similar topics

21
6580
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 Workshop program: hcw.exe that's included with Visual Basic. This exact same file compiled perfectly with no notes, warnings or errors prior to reformatting my system. Prior to the reformatting, I copied the help.rtf file onto a CD and checked the box to...
4
3361
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 cmd.Cmd but I would also like to get the man-page-like help for classes and functions. Does anyone know how to do that? Thanks. Sarir
6
4372
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 result in any way. Who can help me, I thank you very very much. list.cpp(main program) //-------------------------------------------------------------------------- - #pragma hdrstop #pragma argsused
6
3032
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 an html authoring tool to help you accomplish? 2. What do you expect from online help for a html authoring tool? 3. What audience do you think a freeware html authoring tool is directed towards?
0
568
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 link doesn't work, basically here is the article: An Exploration Into Launching Context-Sensitive HTML Help with Topic IDs in VB.NET I spent this evening investigating the HTML Help API as implemented in
3
3376
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 numarray, help gives unhelpful responses:
5
3296
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 using "F1" help within the VB IDE. Is this expectation achievable In trying to test my help file in the IDE, I have a solution with 2 projects: the DLL and a tester. VB does not look for my help file; instead, it looks for path to my source code...
8
3245
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 including search the internet for help, but the help is worthless. Any ideas?
10
3380
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 the worst I ever seen. I almost cannot find anything I need, including things I
1
6152
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 default property of object Label. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"' Label = New Object(){Box1, Box2, Box3, Box4, Box5, Box6, Box7, Box8, Box9, Box10, Box11,...
0
9961
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9800
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10778
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10439
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7148
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5824
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4642
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4247
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3252
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.