Solved

Template column values on Edit Command

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

840 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