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

Home Posts Topics Members FAQ

Templated Field in an 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 1354

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

Similar topics

4
2547
by: Javier Gomez | last post by:
I have a query field which is a non editable field because is a function's result. Due to I need to edit the information, Can you please suggest me any solution for this problem?? (No matter which one) I tryed to duplicate this field , (copying into a new temporally field) but no success....... continues non editable field :-(((
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 ***
0
1556
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...
2
6290
by: Ismail | last post by:
Hello, I have grid view which can go into edit mode. I have fields one of which is primary key I dont want to display this field but will use this field in my update method. If I make the bound column readonly i get nulls if i set visible to false i get nulls. When visible and not readonly i get value however I dont want people trying to...
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
7698
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
8122
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...
0
7970
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...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
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
3653
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...
1
2113
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
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.