Thank you for the reply. Actually as a matter of fact I am trying the
access the dropdown control from the Row_DataBound method.
I am also trying to do the FindControl on the row I am trying to update
like this:
ddl2 = (DropDownList)e.Row.FindControl("ddlChooseLoc");---> at this
point I am getting
a null value for ddl2
I have defined the variable ddl2 in the base class file (which is
inherited from Page class
placed under app_code folder and my partial class derives from this
base class) as follows:
protected DropDownList ddl2;
I have the CodeBasefile in the @Page set to the base class.
Here is a part of my aspx page:
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="OrderTable.aspx.cs"
Inherits="OrderTable" Title="Untitled Page"
CodeFileBaseClass="OrderTable_Base"%>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<asp:GridView ID="GridView1" runat="server"
DataSourceID="ObjectDataSource1" AllowPaging="True"
AutoGenerateColumns="False" AllowSorting="True"
AutoGenerateEditButton="True"
OnRowDataBound="GridView1_RowDataBound"
OnRowUpdating = "GridView1_RowUpdating"
OnSelectedIndexChanged="GridView1_SelectedIndexCha nged">
<Columns>
</Columns>
<asp:TemplateField HeaderText="Choose Location">
<ItemTemplate>
<asp:DropDownList ID="ddlChooseLoc" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
Thanks
-Siva
clickon wrote:
I am not sure how the Master Page bit fits into this problem because you
havn't said where you are trying to access the GridView from and where the
GridView is (i.e. master or child page for both questions).
Generally the problem with accessing a control within a GridView
TemplateField is that there are lots of the (i.e. one on each row) so you
can't use GridView.FindControl("ChildControlID");.
What you have to do is use find control on a particular row e.g.
GridView.Rows[2].FindControl("ChildControlId");
If you want to set a property on a control based on a set of criteria a good
place to do it is in the RowDataBound event handler. For example the below
code sets the colour of a lable control to Red when the text Value = Invalid
Product
protected void gvwOrderDetails_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (((Label)e.Row.FindControl("lblDescription")) != null)
{
if (((Label)e.Row.FindControl("lblDescription")).Text ==
"Invalid Product")
{
((Label)e.Row.FindControl("lblDescription")).ForeC olor =
System.Drawing.Color.Red;
lblInvalidProduct.Visible = true;
btnNext4.Visible = false;
}
}
}
Please note that i also check to see if the control i am looking for is set
to null to account for rows such as headers etc that don't contain the
control i am looking for.
"Siva" wrote:
Hello
I have a dropdownlist inside the gridview as a template column defined
as follows:
<asp:TemplateField HeaderText="Choose Location">
<ItemTemplate>
<asp:DropDownList ID="ddlChooseLoc" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
I have the gridview inside of a master page- content hierarchy.
I have declared the CodeFileBaseClass in your @ Page directive; I have
also declared a variable of the type dropdownlist in the base class.
When I try to access it from the partial class I am getting a null
value for the dropdownlist variable.
I even tried to a FindControl on the dropdownlist still I am getting a
null.
Any idea what I may be missing?
Thanks
-Siva