Cant find control within EDit Row of GridView .. please halp


A

anonymoushamster

I have a gridview and a dropdown that appears in my custom edit row
( i added it to the edititemtemplate).

However I cant reference it/ find it. The dropdown is in the first
columnd and the below is located within :

public void rowedit(Object sender, GridViewEditEventArgs e)




DropDownList s =
(DropDownList)GridView1.Rows[e.NewEditIndex].Cells[0].FindControl("ddlPersonCode");
Response.Write("ID IS " + s.ID);



This results in a Null reference exception (it hasnt been found)
Please any ideas?
 
Ad

Advertisements

A

anonymoushamster

I have a gridview and a dropdown that appears in my custom edit row
( i added it to the edititemtemplate).

However I cant reference it/ find it. The dropdown is in the first
columnd and the below is located within :

public void rowedit(Object sender, GridViewEditEventArgs e)

DropDownList s =
(DropDownList)GridView1.Rows[e.NewEditIndex].Cells[0].FindControl("ddlPersonCode");
Response.Write("ID IS " + s.ID);

This results in a Null reference exception (it hasnt been found)
Please any ideas?







My aspx code:

<asp:GridView OnRowUpdating="rowupdate" OnRowEditing="rowedit"
OnRowCommand="gridChange" ShowFooter="True" DataKeyNames="ID"
ID="GridView1"
runat="server" AllowPaging="True" AllowSorting="True"
DataSourceID="SqlDataSource1"
CellPadding="4" ForeColor="#333333" GridLines="None"
AutoGenerateColumns="False"
Font-Size="X-Small" Height="356px" Width="2696px" >
<FooterStyle BackColor="#5D7B9D" Font-Bold="True"
ForeColor="White" Width="10px"
Wrap="False" />


<Columns>
<asp:TemplateField HeaderText="PersonCode" >
<ItemTemplate>
<asp:literal ID="Personcodedb" runat="server" Text='<%#
Eval("PersonCode") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlPersonCode" runat="server"
DataTextField="PersonCode" DataValueField="PersonCode" >
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
 
Ad

Advertisements

A

anonymoushamster

I have a gridview and a dropdown that appears in my custom edit row
( i added it to the edititemtemplate).
However I cant reference it/ find it. The dropdown is in the first
columnd and the below is located within :
public void rowedit(Object sender, GridViewEditEventArgs e)
DropDownList s =
(DropDownList)GridView1.Rows[e.NewEditIndex].Cells[0].FindControl("ddlPersonCode");
Response.Write("ID IS " + s.ID);
This results in a Null reference exception (it hasnt been found)
Please any ideas?

My aspx code:

<asp:GridView OnRowUpdating="rowupdate" OnRowEditing="rowedit"
OnRowCommand="gridChange" ShowFooter="True" DataKeyNames="ID"
ID="GridView1"
runat="server" AllowPaging="True" AllowSorting="True"
DataSourceID="SqlDataSource1"
CellPadding="4" ForeColor="#333333" GridLines="None"
AutoGenerateColumns="False"
Font-Size="X-Small" Height="356px" Width="2696px" >
<FooterStyle BackColor="#5D7B9D" Font-Bold="True"
ForeColor="White" Width="10px"
Wrap="False" />

<Columns>
<asp:TemplateField HeaderText="PersonCode" >
<ItemTemplate>
<asp:literal ID="Personcodedb" runat="server" Text='<%#
Eval("PersonCode") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlPersonCode" runat="server"
DataTextField="PersonCode" DataValueField="PersonCode" >
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>

solved = GridView1.Rows[e.NewEditIndex -
1].Cells[0].FindControl("ddlPersonCode")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top