Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6884733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:32:45+00:00 2026-05-27T05:32:45+00:00

I am doing insert/update and delete in gridview. For that I am using ItemTemplate

  • 0

I am doing insert/update and delete in gridview. For that I am using ItemTemplate which contains labels to show the values. But when the gridview is in edit mode, the dropdown lists comes in place of that labels. I want to set the selected values of drop down lists to the values of labels. My drop down lists dont have datasource. I am binding dropdown list from 0 to 99. Below is the code for my edit method.

 protected void grdUsedCatheters_RowEditing(object sender, GridViewEditEventArgs e)
 {
    try
    {
        grdUsedCatheters.EditIndex = e.NewEditIndex;
        BindCatheterGrid();
        DropDownList ddlFrom = (DropDownList)grdUsedCatheters.Rows[e.NewEditIndex].FindControl("ddFrom");
        DropDownList ddlTo = (DropDownList)grdUsedCatheters.Rows[e.NewEditIndex].FindControl("ddTo");
        BindDropDowns(ddlFrom);
        BindDropDowns(ddlTo);

    }
    catch (Exception ex)
    {
        if (ex.HelpLink == null)
            lblMessage.Text = ex.Message;
        else
            lblMessage.Text = ex.HelpLink;
        lblMessage.CssClass = "ERROR";
    }

private void BindDropDowns(DropDownList ddl)
 {
    for (int i = 0; i <= 99; i++)
        ddl.Items.Add(i.ToString());
 }

below is the part of markup of my gridview

<asp:TemplateField HeaderText="Cine Run">
   <ItemTemplate>
        From:&nbsp;<asp:Label ID="lblFrom" runat="server" ><%# Eval("CineRunFrom")%></asp:Label>
        To:&nbsp;<asp:Label ID="lblTo" runat="server"><%# Eval("CineRunTo")%></asp:Label>
   </ItemTemplate>
   <EditItemTemplate>
       From:&nbsp;<asp:DropDownList ID="ddFrom" runat="server" Width="50px">
     </asp:DropDownList>
       To:&nbsp;<asp:DropDownList ID="ddTo" runat="server" Width="50px">
     </asp:DropDownList>
   </EditItemTemplate>
  <FooterTemplate>
       From:&nbsp;<asp:DropDownList ID="ddFromF" runat="server" Width="50px">              </asp:DropDownList>
       To:&nbsp;<asp:DropDownList ID="ddToF" runat="server" Width="50px">                                        </asp:DropDownList>
  </FooterTemplate>
 </asp:TemplateField>

} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:32:46+00:00Added an answer on May 27, 2026 at 5:32 am

    Retrieve the values of label’s before setting grdUsedCatheters.EditIndex = e.NewEditIndex and calling BindCatheterGrid() method and then after populating the DropDownLists set their selected value accordingly. Like this:

    protected void grdUsedCatheters_RowEditing(object sender, GridViewEditEventArgs e)
     {
        try
        {
            Label lblFrom = (Label)grdUsedCatheters.Rows[e.NewEditIndex].FindControl("lblFrom"); //lblFrom is the ID of label
    
            grdUsedCatheters.EditIndex = e.NewEditIndex;
            BindCatheterGrid();
            DropDownList ddlFrom = (DropDownList)grdUsedCatheters.Rows[e.NewEditIndex].FindControl("ddFrom");
            DropDownList ddlTo = (DropDownList)grdUsedCatheters.Rows[e.NewEditIndex].FindControl("ddTo");
            BindDropDowns(ddlFrom);
            BindDropDowns(ddlTo);
    
            ddlFrom.Text = lblFrom.Text;
    
        }
        catch (Exception ex)
        {
            if (ex.HelpLink == null)
                lblMessage.Text = ex.Message;
            else
                lblMessage.Text = ex.HelpLink;
            lblMessage.CssClass = "ERROR";
        }
    
    }
    

    Edit
    and also change your gridview markup like this:

    <asp:TemplateField HeaderText="Cine Run">
       <ItemTemplate>
            From:&nbsp;<asp:Label ID="lblFrom" runat="server" Text='<%# Eval("CineRunFrom")%>' />
            To:&nbsp;<asp:Label ID="lblTo" runat="server" Text='<%# Eval("CineRunTo")%>' />
       </ItemTemplate>
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a UITableView in which I am doing batch insert/delete/reloads into. Every
I want to write a DBI wrapper, provide select/insert/update/delete, and users can choose which
Frequently I found myself doing some functions to insert/delete/update in one or more tables
I have an AFTER INSERT OR UPDATE OR DELETE trigger that I'm writing to
I'm doing a bulk insert of a CSV file into SQL Server 2005, using
I tried to create a database by the following command: mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,ALTER,INDEX,DROP, ->
I am trying to do an Insert, Update and Delete on a table in
When doing an INSERT with a lot of data, ie: INSERT INTO table (mediumtext_field)
I'm doing an insert query where most of many columns would need to be
I'm doing an INSERT INTO query in order to initialize a new table. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.