Solved

Template column values on Edit Command

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp.net bundle 8 47
Code works but how can I download the file? 20 67
c# regex: extract & replace text between braces 6 45
Help with C#, MVC, razor. 6 23
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: …
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now