<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Data Presentation Controls</title><link>http://forums.asp.net/24.aspx</link><description>ASP.NET data-bound controls such as the DataGrid, DataList, GridView, FormView, DetailsView, and Repeater Controls.  &lt;a href="http://aspadvice.com/SignUp/list.aspx?l=23&amp;c=17" target="_blank"&gt;Email List&lt;/a&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: problems with GridView SelectedRow</title><link>http://forums.asp.net/thread/3261624.aspx</link><pubDate>Sat, 27 Jun 2009 10:16:18 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3261624</guid><dc:creator>b0oNz</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3261624.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=24&amp;PostID=3261624</wfw:commentRss><description>&lt;p&gt;&amp;nbsp;Hi&lt;/p&gt;
&lt;p&gt;Thanks for all the help, I had solved the problem thanks all to&amp;nbsp;your experts help. Really appreciated.&lt;/p&gt;
&lt;p&gt;Stay Happy&lt;br /&gt;Boonz&lt;/p&gt;</description></item><item><title>Re: problems with GridView SelectedRow</title><link>http://forums.asp.net/thread/3261566.aspx</link><pubDate>Sat, 27 Jun 2009 09:40:16 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3261566</guid><dc:creator>anas</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3261566.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=24&amp;PostID=3261566</wfw:commentRss><description>&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/fan/images/icon-quote.gif"&gt; &lt;strong&gt;b0oNz:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;Apparently SelectedRow, SelectedIndex and SelectedDataKey etc will give me the same error message.&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;/p&gt;&lt;p&gt;Because there is no row selected.The mentioned button doesn&amp;#39;t select the row because it&amp;#39;s command name is not set to &amp;quot;Select&amp;quot;.&lt;/p&gt;&lt;p&gt;I think the solution is to get the row in that holds the currently clicked button .&lt;/p&gt;&lt;p&gt;In the AddBT_click event handler , you can get the Row like this:&lt;/p&gt;&lt;p&gt;&lt;pre name="code" class="c-sharp"&gt;        GridViewRow row = (sender as Button).NamingContainer as GridViewRow;
        // get the text of the 3&amp;#39;rd cell.
        // Note: if the 3&amp;#39;rd column in the GridView is set as hidden (visisble=false),any cell in that column will have an empty text.
        string eID = row.Cells[2].Text;&lt;/pre&gt;&lt;br /&gt; &lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: problems with GridView SelectedRow</title><link>http://forums.asp.net/thread/3261556.aspx</link><pubDate>Sat, 27 Jun 2009 09:32:46 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3261556</guid><dc:creator>akhhttar</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3261556.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=24&amp;PostID=3261556</wfw:commentRss><description>&lt;p&gt;Hi,&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;You are getting this error because SelectedRow property of GridView is NULL. If purpose is to get the 2nd Cell value of the grid view row for which Add button is clicked then use following code&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;((GridViewRow)((Button)sender).Parent.Parent).Cells[2].Text&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Thanks&lt;/p&gt;&lt;p&gt;Muhammad Akhtar Shiekh&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: problems with GridView SelectedRow</title><link>http://forums.asp.net/thread/3261547.aspx</link><pubDate>Sat, 27 Jun 2009 09:23:36 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3261547</guid><dc:creator>chintanpshah</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3261547.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=24&amp;PostID=3261547</wfw:commentRss><description>&lt;p&gt;Refer to:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.codeproject.com/KB/webforms/GridView_all_in_one.aspx"&gt;http://www.codeproject.com/KB/webforms/GridView_all_in_one.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.asp.net/LEARN/3.5-SP1/video-290.aspx"&gt;http://www.asp.net/LEARN/3.5-SP1/video-290.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://asyncpostback.com/02_UpdatePanel/04_FullEditing.aspx"&gt;http://asyncpostback.com/02_UpdatePanel/04_FullEditing.aspx&lt;/a&gt;&lt;/p&gt;</description></item><item><title>problems with GridView SelectedRow</title><link>http://forums.asp.net/thread/3261517.aspx</link><pubDate>Sat, 27 Jun 2009 08:44:04 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3261517</guid><dc:creator>b0oNz</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3261517.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=24&amp;PostID=3261517</wfw:commentRss><description>&lt;p&gt;Hi I&amp;#39;m not really good at programming thus I need some guidance from you experts.&lt;/p&gt;&lt;p&gt;I&amp;#39;m using Visual Studio 2005, asp.net, C#.&lt;/p&gt;&lt;p&gt;I wanted to add things into my database when the user clicks the add button that is created in the item template field of the GridView control. This is how my item template field looks like:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div style="position:absolute;left:-10000px;top:0px;width:1px;height:1px;overflow-x:hidden;overflow-y:hidden;" id="_mcePaste"&gt;&amp;lt;asp:TemplateField ShowHeader=&amp;quot;False&amp;quot;&amp;gt;&lt;/div&gt;
&lt;div style="position:absolute;left:-10000px;top:0px;width:1px;height:1px;overflow-x:hidden;overflow-y:hidden;" id="_mcePaste"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;ItemTemplate&amp;gt;&lt;/div&gt;
&lt;div style="position:absolute;left:-10000px;top:0px;width:1px;height:1px;overflow-x:hidden;overflow-y:hidden;" id="_mcePaste"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;asp:Button ID=&amp;quot;AddBT&amp;quot; runat=&amp;quot;server&amp;quot; CausesValidation=&amp;quot;False&amp;quot;&lt;/div&gt;
&lt;div style="position:absolute;left:-10000px;top:0px;width:1px;height:1px;overflow-x:hidden;overflow-y:hidden;" id="_mcePaste"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;OnClick=&amp;quot;AddBT_Click&amp;quot; Text=&amp;quot;Add to Cart&amp;quot; CommandName=&amp;quot;Delete&amp;quot; /&amp;gt;&lt;/div&gt;
&lt;div style="position:absolute;left:-10000px;top:0px;width:1px;height:1px;overflow-x:hidden;overflow-y:hidden;" id="_mcePaste"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;/ItemTemplate&amp;gt;&lt;/div&gt;
&lt;div style="position:absolute;left:-10000px;top:0px;width:1px;height:1px;overflow-x:hidden;overflow-y:hidden;" id="_mcePaste"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;ControlStyle Width=&amp;quot;80px&amp;quot; /&amp;gt;&lt;/div&gt;
&lt;div style="position:absolute;left:-10000px;top:0px;width:1px;height:1px;overflow-x:hidden;overflow-y:hidden;" id="_mcePaste"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;/asp:TemplateField&amp;gt;&lt;/div&gt;&lt;p&gt;&lt;p&gt;&amp;lt;asp:TemplateField ShowHeader=&amp;quot;False&amp;quot;&amp;gt;&lt;/p&gt;&lt;p&gt;&amp;lt;ItemTemplate&amp;gt;&lt;/p&gt;&lt;p&gt;&amp;lt;asp:Button ID=&amp;quot;AddBT&amp;quot; runat=&amp;quot;server&amp;quot; CausesValidation=&amp;quot;False&amp;quot;&amp;nbsp;OnClick=&amp;quot;AddBT_Click&amp;quot; Text=&amp;quot;Add to Cart&amp;quot; /&amp;gt;&lt;/p&gt;&lt;p&gt;&amp;lt;/ItemTemplate&amp;gt;&lt;/p&gt;&lt;p&gt;&amp;lt;ControlStyle Width=&amp;quot;80px&amp;quot; /&amp;gt;&lt;/p&gt;&lt;p&gt;&amp;lt;/asp:TemplateField&amp;gt;&lt;/p&gt;&lt;p&gt;So every line in the gridview will have the Add button.&lt;/p&gt;&lt;p&gt;So on click it will run the codes that is on my .cs file and this is when I recieve this error &amp;quot;Object reference not set to an instance of an object.&amp;quot;&amp;nbsp;&lt;/p&gt;&lt;p&gt;I slowly elimate the code and found out that the source of the problem is this:&lt;/p&gt;&lt;p&gt;string eID = GridView1.SelectedRow.Cells[2].Text;&lt;/p&gt;&lt;p&gt;Apparently SelectedRow, SelectedIndex and SelectedDataKey etc will give me the same error message.&lt;/p&gt;&lt;p&gt;Can anyone help me with this? Couldn&amp;#39;t find my answer after Googling it for hours.&lt;/p&gt;&lt;/p&gt;</description></item></channel></rss>