Solved

Template column values on Edit Command

Posted on 2007-12-03
5
397 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
  • 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

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…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

770 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