F
Frank
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(object sender, EventArgs e)
{
int int_temp =
Convert.ToInt32(listAdapter.FindAccountInList(DDL_BlockList.SelectedValue,
((DropDownList)sender).SelectedValue));
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.Visible = true;
}
else
{
LBL_Warn.Visible = 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" AutoGenerateColumns="False"
DataKeyNames="ID"
DataSourceID="ObjectDataSource2" OnRowUpdated="AdjustUnitDisplay"
OnRowDeleted="AdjustUnitDisplay" AllowPaging="True">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:TemplateField HeaderText="Account" SortExpression="Account">
<EditItemTemplate>
<asp
ropDownList ID="DropDownList1" runat="server"
DataSourceID="DDL_Accts_DataSource"
DataTextField="Account" DataValueField="Account" AutoPostBack="True"
SelectedValue='<%# Bind("Account") %>' OnSelectedIndexChanged="CheckForDup"
Width="65px">
</asp
ropDownList>
<asp
ropDownList ID="DropDownList2" runat="server"
DataSourceID="DDL_Lname_DataSource"
DataTextField="Lname" DataValueField="Lname" Width="90px">
</asp
ropDownList>
<asp:ObjectDataSource ID="DDL_Lname_DataSource" runat="server"
InsertMethod="Insert" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetLnameByAccount"
TypeName="Desk_A_ServerTableAdapters.CustomerTableAdapter">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="Account"
PropertyName="SelectedValue"
Type="String" />
</SelectParameters>
<InsertParameters>
<asp
arameter Name="Account" Type="String" />
<asp
arameter Name="broker" Type="String" />
<asp
arameter Name="key" Type="String" />
<asp
arameter Name="Fname" Type="String" />
<asp
arameter Name="Lname" Type="String" />
</InsertParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="DDL_Accts_DataSource" runat="server"
InsertMethod="Insert" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetCustomerByBrokerID"
TypeName="Desk_A_ServerTableAdapters.CustomerTableAdapter">
<SelectParameters>
<asp:SessionParameter Name="broker" SessionField="IB_Acct" Type="String" />
</SelectParameters>
<InsertParameters>
<asp
arameter Name="Account" Type="String" />
<asp
arameter Name="broker" Type="String" />
<asp
arameter Name="key" Type="String" />
<asp
arameter Name="Fname" Type="String" />
<asp
arameter Name="Lname" Type="String" />
</InsertParameters>
</asp:ObjectDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Account")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="# of Contracts" SortExpression="value">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("value") %>'
Width="50px"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("value")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Type" SortExpression="type">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("type") %>'
Width="50px"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("type")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
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(object sender, EventArgs e)
{
int int_temp =
Convert.ToInt32(listAdapter.FindAccountInList(DDL_BlockList.SelectedValue,
((DropDownList)sender).SelectedValue));
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.Visible = true;
}
else
{
LBL_Warn.Visible = 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" AutoGenerateColumns="False"
DataKeyNames="ID"
DataSourceID="ObjectDataSource2" OnRowUpdated="AdjustUnitDisplay"
OnRowDeleted="AdjustUnitDisplay" AllowPaging="True">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:TemplateField HeaderText="Account" SortExpression="Account">
<EditItemTemplate>
<asp
DataSourceID="DDL_Accts_DataSource"
DataTextField="Account" DataValueField="Account" AutoPostBack="True"
SelectedValue='<%# Bind("Account") %>' OnSelectedIndexChanged="CheckForDup"
Width="65px">
</asp
<asp
DataSourceID="DDL_Lname_DataSource"
DataTextField="Lname" DataValueField="Lname" Width="90px">
</asp
<asp:ObjectDataSource ID="DDL_Lname_DataSource" runat="server"
InsertMethod="Insert" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetLnameByAccount"
TypeName="Desk_A_ServerTableAdapters.CustomerTableAdapter">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="Account"
PropertyName="SelectedValue"
Type="String" />
</SelectParameters>
<InsertParameters>
<asp
<asp
<asp
<asp
<asp
</InsertParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="DDL_Accts_DataSource" runat="server"
InsertMethod="Insert" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetCustomerByBrokerID"
TypeName="Desk_A_ServerTableAdapters.CustomerTableAdapter">
<SelectParameters>
<asp:SessionParameter Name="broker" SessionField="IB_Acct" Type="String" />
</SelectParameters>
<InsertParameters>
<asp
<asp
<asp
<asp
<asp
</InsertParameters>
</asp:ObjectDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Account")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="# of Contracts" SortExpression="value">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("value") %>'
Width="50px"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("value")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Type" SortExpression="type">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("type") %>'
Width="50px"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("type")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>