473,569 Members | 2,836 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Templated Editable GridView Problem

Hello All,

I am working with VS.NET 2005 and I have an editable GridView whose HTML
markup is shown below.

In short, when the user clicks on the Edit button, one of the textboxes is
replaced with a DropDownList that displays account numbers in a list. If the
user selects an account from the DropDownList that already exists in the
list, I wish to hide the 'Update' button or column, along with displaying a
warning message. I try to do this with this code behind:
protected void CheckForDup(obj ect sender, EventArgs e)

{

int int_temp =
Convert.ToInt32 (listAdapter.Fi ndAccountInList (DDL_BlockList. SelectedValue,
((DropDownList) sender).Selecte dValue));

if (int_temp != 0)

{

GridView Temp = new GridView();

Temp = (GridView)Page. FindControl("GV _Accts");

Temp.Columns[0].Visible = false;
LBL_Warn.Text = "That Account Already Exists in the List!";

LBL_Warn.Visibl e = true;

}

else

{

LBL_Warn.Visibl e = false;

}

}

However, when it runs, I get an "Object reference not set to an instance of
an object." exception.

It doesn't like the line that reads 'Temp.Columns[0].Visible = false;'

Anyone have any suggestions please?

Thanks in advance

<asp:GridView ID="GV_Accts" runat="server" AutoGenerateCol umns="False"
DataKeyNames="I D"

DataSourceID="O bjectDataSource 2" OnRowUpdated="A djustUnitDispla y"
OnRowDeleted="A djustUnitDispla y" AllowPaging="Tr ue">

<Columns>

<asp:CommandFie ld ShowDeleteButto n="True" ShowEditButton= "True" />

<asp:TemplateFi eld HeaderText="Acc ount" SortExpression= "Account">

<EditItemTempla te>

<asp:DropDownLi st ID="DropDownLis t1" runat="server"
DataSourceID="D DL_Accts_DataSo urce"

DataTextField=" Account" DataValueField= "Account" AutoPostBack="T rue"
SelectedValue=' <%# Bind("Account") %>' OnSelectedIndex Changed="CheckF orDup"
Width="65px">

</asp:DropDownLis t>

<asp:DropDownLi st ID="DropDownLis t2" runat="server"
DataSourceID="D DL_Lname_DataSo urce"

DataTextField=" Lname" DataValueField= "Lname" Width="90px">

</asp:DropDownLis t>&nbsp;

<asp:ObjectData Source ID="DDL_Lname_D ataSource" runat="server"

InsertMethod="I nsert" OldValuesParame terFormatString ="original_{ 0}"
SelectMethod="G etLnameByAccoun t"

TypeName="Desk_ A_ServerTableAd apters.Customer TableAdapter">

<SelectParamete rs>

<asp:ControlPar ameter ControlID="Drop DownList1" Name="Account"
PropertyName="S electedValue"

Type="String" />

</SelectParameter s>

<InsertParamete rs>

<asp:Paramete r Name="Account" Type="String" />

<asp:Paramete r Name="broker" Type="String" />

<asp:Paramete r Name="key" Type="String" />

<asp:Paramete r Name="Fname" Type="String" />

<asp:Paramete r Name="Lname" Type="String" />

</InsertParameter s>

</asp:ObjectDataS ource>

<asp:ObjectData Source ID="DDL_Accts_D ataSource" runat="server"

InsertMethod="I nsert" OldValuesParame terFormatString ="original_{ 0}"
SelectMethod="G etCustomerByBro kerID"

TypeName="Desk_ A_ServerTableAd apters.Customer TableAdapter">

<SelectParamete rs>

<asp:SessionPar ameter Name="broker" SessionField="I B_Acct" Type="String" />

</SelectParameter s>

<InsertParamete rs>

<asp:Paramete r Name="Account" Type="String" />

<asp:Paramete r Name="broker" Type="String" />

<asp:Paramete r Name="key" Type="String" />

<asp:Paramete r Name="Fname" Type="String" />

<asp:Paramete r Name="Lname" Type="String" />

</InsertParameter s>

</asp:ObjectDataS ource>

</EditItemTemplat e>

<ItemTemplate >

<asp:Label ID="Label1" runat="server" Text='<%# Bind("Account")
%>'></asp:Label>

</ItemTemplate>

</asp:TemplateFie ld>

<asp:TemplateFi eld HeaderText="# of Contracts" SortExpression= "value">

<EditItemTempla te>

<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("value") %>'
Width="50px"></asp:TextBox>

</EditItemTemplat e>

<ItemTemplate >

<asp:Label ID="Label2" runat="server" Text='<%# Bind("value")
%>'></asp:Label>

</ItemTemplate>

</asp:TemplateFie ld>

<asp:TemplateFi eld HeaderText="Typ e" SortExpression= "type">

<EditItemTempla te>

<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("type") %>'
Width="50px"></asp:TextBox>

</EditItemTemplat e>

<ItemTemplate >

<asp:Label ID="Label3" runat="server" Text='<%# Bind("type")
%>'></asp:Label>

</ItemTemplate>

</asp:TemplateFie ld>

</Columns>

</asp:GridView>
Sep 19 '06 #1
0 1555

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1249
by: Shafia | last post by:
Hi, My GridView has templated controls in it and I'm binding to an ObjectDataSource. The problem is it refused to bind to my grid column "ColumnName" which is also an UpdateCommand Parameter for the ObjectDataSource. It displays the following error "DataBinding: 'System.String' does not contain a property with the name 'ColumnName'. I've...
2
2133
by: Anonieko | last post by:
Hello ASPNET guru's, What is a clean way to go around the problem of displaying a GridView templated column where data can contain Single Quote ( ' )? I maybe too naive, but this is of course a common scenario. Scenario: * My database returns names that can contain single quote.
3
2136
by: Mike P | last post by:
Is it possible to make an editable gridview so that certain rows are editable and other are not editable, dependent upon a value in one of the rows columns? *** Sent via Developersdex http://www.developersdex.com ***
2
2017
by: dba56 | last post by:
In an ASP.Net 2.0 page using SQL Server 2K, I have a editable gridview that is bound to a SQLDataSource using stored procedures for its select and update queries. The grid works fine but is slow due to rebinding on postbacks when the edit, save or cancel buttons are clicked. So I set "enablecache = True" for the SQLDataSource and it is...
0
1354
by: Frank | last post by:
Hello All, I am working with VS.NET 2005 and I have an editable GridView whose HTML markup is shown below. In short, when the user clicks on the Edit button, one of the textboxes is replaced with a DropDownList that displays account numbers in a list. If the user selects an account from the DropDownList that already exists in the list, I...
1
1902
by: news-server.maine.rr.com | last post by:
Hi, I have the following bound to a database column and want the URL field to be editable in the GridView control. When the "Edit" link is clicked the field remains readOnly. <asp:HyperLinkField DataTextField="URL" HeaderText="URL" DataNavigateUrlFields="URL" Target="_blank" /> How can I make a hyperlink field that is bound to data...
4
2530
by: Mark Olbert | last post by:
I'm running into a well-described issue in the ASPNET model that I haven't found a good work around for. I have a GridView to which I dynamically add data-bound TemplateFields at run-time. The specific fields that are added depend on the state of the application. The contents of these fields displays properly after they are first...
2
4311
by: =?Utf-8?B?TWljaGFlbCBkZSBWZXJh?= | last post by:
To all, I'm trying to bind a dataset to a listbox control that is in a gridview's templated field. However, in the code behind the intellisense does not recognize the ID name of my listbox control....thus not giving me an opportunity to bind the listbox's datasource to a dataview. Can you make any recommendations? I'm trying to put a...
4
9773
by: mohaaron | last post by:
This seems like it should be simple to do but for some reason I have been unable to make it work. I would like to databind a SqlDataSource to a GridView during the click event of a button. This sounds easy but the next requirement is that the GridView is editable. So I have included the SelectCommand and the UpdateCommand on the...
0
7695
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...
0
7612
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...
0
7922
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6281
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5218
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...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2111
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
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
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...

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.