Solved

Template column values on Edit Command

Posted on 2007-12-03
5
400 Views
Last Modified: 2013-11-06
I have a template column that has a drop down list. The values for this column are assigned in the Item Databound event.
I have the following issues:
 When I click on the Edit button in the edittemplate, the Template column loose there values. I want this row to start in edit mode, however the template columns should still retain there values.

How do I achieve this. Thanks in advance.
0
Comment
Question by:VD1234
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 12

Expert Comment

by:needo_jee
ID: 20397806
when you create a templated column . bydefault controls are placed in edite template according to selected dataType for that column and data is not lost on edit .. but for that you need to make sure that you are rebinding to datasource after its mode is changed to edit.

2nd if you are putting conrols in templated field manully then you need to bind yourself ..
0
 

Author Comment

by:VD1234
ID: 20397938
Data is not lost. What I actually want is for example if I have a drop down list in the edittemplate, I want the selectedvalue to remain the same even after the edit buton is clicked. But the drop down has no selected value as soon as the Edit button is clicked.

I bind the datagrid as follows:
protected void dgDynamicFields_Edit(object source, DataGridCommandEventArgs e)
        {
            // Enter edit mode
            dgDynamicFields.EditItemIndex = e.Item.ItemIndex;
            dtDynamic = objAdmin.Get_DynamicFields().Tables[1];
            BindGrid();
       
        }
0
 
LVL 12

Accepted Solution

by:
needo_jee earned 500 total points
ID: 20398252
//here is default generated code for GridView from Designer
//ASPX
 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnDataBound="GridView1_DataBound" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating">
            <Columns>
                <asp:TemplateField HeaderText="TestID">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("TestID") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("TestID") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="TestName">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("TestName") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("TestName") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:CommandField ShowEditButton="True" />
            </Columns>
        </asp:GridView>


//code behind

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GridView1.DataSource = GetDataCource();
            GridView1.DataBind();
        }
       
    }

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
       
            GridView1.EditIndex = e.NewEditIndex;    
    }

// after hit edite button all data is still there..

thanks
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20952973
Forced accept.

Computer101
Community Support Moderator
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question