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

  • SEARCH
  • Home
  • 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 6904729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:05:50+00:00 2026-05-27T08:05:50+00:00

I am using VS2005 C#. Currently I have a GridView, and I have changed

  • 0

I am using VS2005 C#.

Currently I have a GridView, and I have changed one of my GridView control to my column name Gender, from the default TextBox to a DropDownList, which I gave the ID of the control to GenderList, and it contains 2 values, M and F.

I have a default update statement which is able to update the GridView after edit, which is the following:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString=
"<%$ ConnectionStrings:SODConnectionString %>" UpdateCommand="UPDATE 
[UserMasterData] SET [Name] = @Name, [Age] = @Age, [ContactNo]=@ContactNo,
 [Address]=@Address, [Gender]=@Gender"/>

The above UPDATE query works perfectly, and now I have changed my Gender textbox to a dropdownlist, the UPDATE query gave me an error which says:

Must declare the scalar variable "@Gender".

I assume the UPDATE query couldn’t find the value from my Gender column.

I tried to modify the UPDATE query to @GenderList, but it did not work as well.

Anyone knows what I should do do the UPDATE query so that my UPDATE query can find the value from my GenderList dropdownlist in my Gender column?

Thank you.


Below is my previous Gender column with a textbox control:

                <asp:BoundField  HeaderText="Gender" 
                DataField="Gender" 
                SortExpression="Gender"></asp:BoundField>

Below is my Gender with the dropdownlist control:

    <asp:TemplateField HeaderText="Gender" SortExpression="Gender" >
        <EditItemTemplate>
            <asp:DropDownList ID="GenderList" runat="server" Width="50px" >
                <asp:ListItem>M</asp:ListItem>
                <asp:ListItem>F</asp:ListItem>
            </asp:DropDownList>
        </EditItemTemplate>
        <ItemTemplate>

EDIT:

Tried implementing RowDatBound and onRowUpdating:


RowDatBound


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    DataRowView dRowView = (DataRowView)e.Row.DataItem;
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        if ((e.Row.RowState & DataControlRowState.Edit) > 0)
        {
            DropDownList genderList= (DropDownList)e.Row.FindControl("GenderList");
            genderList.SelectedValue = dRowView[2].ToString();
        }
    }
}

RowUpdating.aspx.cs


protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{

DropDownList genderSelect =(DropDownList)GridView1.Rows[e.RowIndex].FindControl("GenderList");

SqlDataSource1.UpdateParameters["Gender"].DefaultValue = 
genderSelect.SelectedValue; --> error says not set to an instance of an object

}
  • 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-27T08:05:50+00:00Added an answer on May 27, 2026 at 8:05 am

    If you are using SqlDataSource and updating data via it then all you have to do is to set 2 way binding for the dropdownlist GenderList.

    You can set this via the designer or directly in source also

     <EditItemTemplate>
                    <asp:DropDownList ID="GenderList" runat="server" 
                        SelectedValue='<%# Bind("Gender") %>'>
                        <asp:ListItem>M</asp:ListItem>
                        <asp:ListItem>F</asp:ListItem>
                    </asp:DropDownList>
                </EditItemTemplate>
    

    notice that here 2 way binding is being used.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using VS2005. Currently I have a delete linkButton in my gridview, and
I'm currently using default implementation of STL for VS2005 and I'm not really satisfied
I am using VS2005 C# and SQL Server 2005. I have a GridView and
I have written a DLL in C# using VS2005. Currently the DLL is showing
I have to build some C source files using Visual Studio (currently using VS2008)
I'm currently using VS2005 Profesional and .NET 2.0, and since our project is rather
Using VS2005/2008 as a resource editor, one of the options in the Add Resource
I have a small website developed using VS2005 and mySQl, it's just 2 webforms
I have a Windows 7 machine on which I am using VS2005. .Net 2.0
I am using VS2005 C# and SQL Server 2005. Currently I am able to

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.