accessing control in EditItemTemplate of DataList

Discussion in 'ASP .Net Web Controls' started by R.A.M., Dec 19, 2006.

  1. R.A.M.

    R.A.M. Guest

    Hello,
    I am learning ASP.NET.
    On .aspx page I have a data-list with text-box that I would like to read
    during line modification.

    <asp:DataList ...
    OnEditCommand="Sample_Edit" >
    ...
    <EditItemTemplate>
    ...
    <asp:TextBox ID="SampleEdit" runat="server" />
    ...
    </EditItemTemplate>
    ...
    </asp:DataList>

    In code-behind I have:

    protected void Sample_Edit(object sender, DataListCommandEventArgs e)
    {
    ...
    string Sample = ((TextBox)e.Item.FindControl("SampleEdit")).Text; //
    here problem
    ...
    }

    The problem is that although e.Item is fine, FindControl returns null.
    Could you help me to programme it correctly?
    Thank you !!!
    /RAM/
     
    R.A.M., Dec 19, 2006
    #1
    1. Advertising

  2. R.A.M.

    R.A.M. Guest

    I have also tried this way:
    Sample =
    ((TextBox)SampleDataList.Items[e.Item.ItemIndex].FindControl("SampleEdit")).Text;

    and this way:
    Sample =
    ((TextBox)SampleDataList.SelectedItem.FindControl("SampleEdit")).Text;

    but it doesn't work, either.

    U¿ytkownik "R.A.M." <> napisa³ w wiadomo¶ci
    news:em9n83$qti$...
    > Hello,
    > I am learning ASP.NET.
    > On .aspx page I have a data-list with text-box that I would like to read
    > during line modification.
    >
    > <asp:DataList ...
    > OnEditCommand="Sample_Edit" >
    > ...
    > <EditItemTemplate>
    > ...
    > <asp:TextBox ID="SampleEdit" runat="server" />
    > ...
    > </EditItemTemplate>
    > ...
    > </asp:DataList>
    >
    > In code-behind I have:
    >
    > protected void Sample_Edit(object sender, DataListCommandEventArgs e)
    > {
    > ...
    > string Sample = ((TextBox)e.Item.FindControl("SampleEdit")).Text; //
    > here problem
    > ...
    > }
    >
    > The problem is that although e.Item is fine, FindControl returns null.
    > Could you help me to programme it correctly?
    > Thank you !!!
    > /RAM/
    >
     
    R.A.M., Dec 20, 2006
    #2
    1. Advertising

  3. R.A.M.

    R.A.M. Guest

    I have also tried this way:
    Sample =
    ((TextBox)SampleDataList.Items[e.Item.ItemIndex].FindControl("SampleEdit")).Text;

    and this way:
    Sample =
    ((TextBox)SampleDataList.SelectedItem.FindControl("SampleEdit")).Text;

    but it doesn't work, either.

    U¿ytkownik "R.A.M." <> napisa³ w wiadomo¶ci
    news:em9n83$qti$...
    > Hello,
    > I am learning ASP.NET.
    > On .aspx page I have a data-list with text-box that I would like to read
    > during line modification.
    >
    > <asp:DataList ...
    > OnEditCommand="Sample_Edit" >
    > ...
    > <EditItemTemplate>
    > ...
    > <asp:TextBox ID="SampleEdit" runat="server" />
    > ...
    > </EditItemTemplate>
    > ...
    > </asp:DataList>
    >
    > In code-behind I have:
    >
    > protected void Sample_Edit(object sender, DataListCommandEventArgs e)
    > {
    > ...
    > string Sample = ((TextBox)e.Item.FindControl("SampleEdit")).Text; //
    > here problem
    > ...
    > }
    >
    > The problem is that although e.Item is fine, FindControl returns null.
    > Could you help me to programme it correctly?
    > Thank you !!!
    > /RAM/
    >
     
    R.A.M., Dec 20, 2006
    #3
  4. R.A.M.

    R.A.M. Guest

    OK, I solved. SampleEdit is not accessible before edit mode set.

    U¿ytkownik "R.A.M." <> napisa³ w wiadomo¶ci
    news:em9n83$qti$...
    > Hello,
    > I am learning ASP.NET.
    > On .aspx page I have a data-list with text-box that I would like to read
    > during line modification.
    >
    > <asp:DataList ...
    > OnEditCommand="Sample_Edit" >
    > ...
    > <EditItemTemplate>
    > ...
    > <asp:TextBox ID="SampleEdit" runat="server" />
    > ...
    > </EditItemTemplate>
    > ...
    > </asp:DataList>
    >
    > In code-behind I have:
    >
    > protected void Sample_Edit(object sender, DataListCommandEventArgs e)
    > {
    > ...
    > string Sample = ((TextBox)e.Item.FindControl("SampleEdit")).Text; //
    > here problem
    > ...
    > }
    >
    > The problem is that although e.Item is fine, FindControl returns null.
    > Could you help me to programme it correctly?
    > Thank you !!!
    > /RAM/
    >
     
    R.A.M., Dec 20, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nevyn Twyll
    Replies:
    8
    Views:
    1,941
  2. Luis Esteban Valencia
    Replies:
    1
    Views:
    498
    John Saunders
    Jan 6, 2005
  3. Hans Merkl
    Replies:
    3
    Views:
    5,728
    elizas
    Mar 22, 2010
  4. Nathan Sokalski

    Accessing a control in the EditItemTemplate

    Nathan Sokalski, Jun 21, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    447
    marss
    Jun 21, 2007
  5. R.A.M.

    accesing control in EditItemTemplate of DataList

    R.A.M., Dec 19, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    167
    R.A.M.
    Dec 19, 2006
Loading...

Share This Page