Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    Minneapolis, Minnesota, USA
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Just trying to update datagrid (asp.net)

    I had a datagrid set up as bound columns and everything updated perfectly. Then the user wanted to add data, so I changed the bound columns to item template columns. The add works perfectly, but the update is not. The reason why I think is that on bound columns, you can do e.Item.Cells(#) where # is the number of the column. On template columns, e.Item.Cells(0), for example, comes out blank. Here's how I have my template columns set up (I only have two columns here)


    <ASP:TemplateColumn HeaderText="ADV CODE" >
    <FooterTemplate>
    <asp:TextBox ID="ADVCODE" Columns="5" Runat="server"></asp:TextBox>
    </FooterTemplate>
    <ItemTemplate>
    <%# Container.DataItem("ADV_CODE") %>
    </ItemTemplate>
    </ASP:TemplateColumn>
    <ASP:TemplateColumn HeaderText="Description">
    <FooterTemplate>
    <asp:TextBox EnableViewSTate=True Columns="5" ID=DESCRIPTION Runat="server">
    </asp:TextBox>
    </FooterTemplate>
    <ItemTemplate>
    <asp:TextBox EnableViewState=True id=DESCRIPTION1 runat="server"
    Text='<%# DataBinder.Eval(Container, "DataItem.DESCRIPTION") %>'>
    </asp:TextBox>
    </ItemTemplate>
    </ASP:TemplateColumn>


    So since the fields is in the textbox, how do I call it in to represent the field when I'm updating? I'm stumped and would be ever so grateful for any suggestions anyone might have.
    Carpy Diem, it&#39;s .

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Just trying to update datagrid (asp.net)

    You'll probably want to include an EditItemTemplate for each column.

    You can then use the DataGrid's UpdateCommand method to write the updated values.

    Also, one technique I use frequently is to create named controls in each template that are prefixed with the action. For instance, I would name the PersonId label "PersonId" in the ItemTemplate, and I would name the PeresonId TextBox "EditPersonId" in the EditItemTemplate. Then, I use the e.Item.FindControl("EditPersonId") to read the value (of course, I have to cast it to a TextBox, then i can use its text property).

    Hope this helps!

  3. #3
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    Minneapolis, Minnesota, USA
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Just trying to update datagrid (asp.net)

    Thanks, Mark!

    I knew it was something I wasn't getting <img src=/S/doh.gif border=0 alt=doh width=15 height=15> and your explanation is very helpful.
    Carpy Diem, it&#39;s .

  4. #4
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    Minneapolis, Minnesota, USA
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Just trying to update datagrid (asp.net)

    Mark,

    Yippee! It worked! Too bad I'm going on vacation in about 10 minutes but at least I know what to do next when I get back. Oh, and I think I'll get a tattoo while I'm gone saying <span style="background-color: #FFFF00; color: #FFFF00; font-weight: bold">runat="server"</span hide> since I spent about 15 minutes trying to figure out why the first column was no longer displaying....
    Carpy Diem, it&#39;s .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •