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 9177677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:22:50+00:00 2026-06-17T17:22:50+00:00

Hopefully this is a relative quick question for the experts out there! I have

  • 0

Hopefully this is a relative quick question for the experts out there!

I have a Update GridView function that has 5 drop down lists. These 5 lists bind to the same DataTable but the end user (client) cannot specify the same SelectedValue more than once. Group01 is covered by a RequiredFieldValidator so they must specify at least one group.

The issue I have is that what I’ve made the for CustomValidation is a bool that compares the selectedValue’s to make sure they are not the same. However, I can’t directly go to say ‘ddGroup01’ or ‘ddGroup02’ as it doesnt exists in the current context.

So my question, what do I need to do to get the DropDown Lists to exist for the server validation?

aspx page.

           <asp:GridView ID="gvEditUser" runat="server" AllowPaging="True" AutoGenerateColumns="False" OnRowDataBound="gvEditUser_RowDataBound" OnRowCancelingEdit="gvEditUser_RowCancelingEdit" OnRowEditing="gvEditUser_RowEditing" OnRowUpdating="gvEditUser_RowUpdating" OnRowDeleting="gvEditUser_RowDeleting" CellPadding="4" ForeColor="#333333" GridLines="None">
        <AlternatingRowStyle BackColor="White" />
        <Columns>
            <asp:TemplateField HeaderText="User ID">
                <ItemTemplate>
                    <asp:Label ID="lbUserID" runat="server" Text='<%# Eval("userid") %>' ></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Full Name">
                <ItemTemplate>
                    <asp:Label ID="lbFullName" runat="server" Text='<%# Eval("fullname") %>' ></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="tbFullName" runat="server" Text='<%# Eval("fullname") %>' ></asp:TextBox>
                    <asp:RegularExpressionValidator ID="val_reg_FullName" runat="server" ErrorMessage="Not a valid Full Name." ControlToValidate="tbFullName" ValidationExpression="^[A-Z][a-zA-Z']+[ ]+[A-Z][a-zA-Z'\- ]*$" CssClass="password_red_fail" Display="None"></asp:RegularExpressionValidator>
                    <asp:RequiredFieldValidator ID="valFullName" runat="server" ErrorMessage="Full Name is required." CssClass="password_red_fail" ControlToValidate="tbFullName" Display="None"></asp:RequiredFieldValidator>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Email">
                <ItemTemplate>
                    <asp:Label ID="lbEmail" runat="server" Text='<%# Eval("email") %>' ></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Group 01">
                <ItemTemplate>
                    <asp:Label ID="lbGroup01" runat="server" Text='<%# Eval("group01") %>' ></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:DropDownList ID="ddGroup01" runat="server"></asp:DropDownList>
                    <asp:RequiredFieldValidator ID="valddGroup01" runat="server" ErrorMessage="Group 01 is required." CssClass="password_red_fail" ControlToValidate="ddGroup01" Display="None"></asp:RequiredFieldValidator>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Group 02">
                <ItemTemplate>
                    <asp:Label ID="lbGroup02" runat="server" Text='<%# Eval("group02") %>' ></asp:Label>
                </ItemTemplate>

                <EditItemTemplate>
                    <asp:DropDownList ID="ddGroup02" runat="server"></asp:DropDownList>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Group 03">
                <ItemTemplate>
                    <asp:Label ID="lbGroup03" runat="server" Text='<%# Eval("group03") %>' ></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:DropDownList ID="ddGroup03" runat="server"></asp:DropDownList>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Group 04">
                <ItemTemplate>
                    <asp:Label ID="lbGroup04" runat="server" Text='<%# Eval("group04") %>' ></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:DropDownList ID="ddGroup04" runat="server"></asp:DropDownList>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Group 05">
                <ItemTemplate>
                    <asp:Label ID="lbGrou05" runat="server" Text='<%# Eval("group05") %>' ></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:DropDownList ID="ddGroup05" runat="server"></asp:DropDownList>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Admin">
                <ItemTemplate>
                    <asp:CheckBox ID="cbAdmin" runat="server" Checked='<%# Convert.ToBoolean(Eval("admin")) %>' Enabled="false" />
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:CheckBox ID="cbAdmin" runat="server" />
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Created by">
                <ItemTemplate>
                    <asp:Label ID="lbCreatedBy" runat="server" Text='<%# Eval("createdby") %>' ></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Last Login">
                <ItemTemplate>
                    <asp:Label ID="lbLastLogin" runat="server" Text='<%# Eval("lastlogin") %>' ></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Edit" ShowHeader="false">
                <ItemTemplate>
                    <asp:LinkButton ID="btnEdit" runat="server" CommandName="Edit" Text="Edit"></asp:LinkButton>
                    <asp:LinkButton ID="btnDelete" runat="server" CommandName="Delete" Text="Delete"></asp:LinkButton>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:LinkButton ID="btnUpdate" runat="server" CommandName="Update" Text="Update"></asp:LinkButton>
                    <asp:LinkButton ID="btnCancel" runat="server" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
                </EditItemTemplate>
            </asp:TemplateField>
        </Columns>
        <EditRowStyle BackColor="#2461BF" />
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="Black" />
        <HeaderStyle BackColor="#507CD1" ForeColor="White" CssClass="size14_text" />
        <PagerStyle BackColor="#2461BF" ForeColor="Black" HorizontalAlign="Center" />
        <RowStyle BackColor="#EFF3FB" />
        <SelectedRowStyle BackColor="#FFFFFF" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#F5F7FB" />
        <SortedAscendingHeaderStyle BackColor="#6D95E1" />
        <SortedDescendingCellStyle BackColor="#E9EBEF" />
        <SortedDescendingHeaderStyle BackColor="#4870BE" />
    </asp:GridView>
    <asp:ValidationSummary ID="valSummary" runat="server" CssClass="password_red_fail" />

A snippet of the code behind. Assuming this is the parts one would need.

protected void gvEditUser_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        if (e.Row.RowState != null)
        {
            if ((e.Row.RowState & DataControlRowState.Edit) > 0)
            {
                DropDownList ddGroup01 = (DropDownList)e.Row.FindControl("ddGroup01");
                ddGroup01.DataTextField = "association";
                ddGroup01.DataValueField = "association";
                ddGroup01.DataSource = load_group();
                ddGroup01.DataBind();
                ddGroup01.Items.Insert(0, new ListItem());

                DropDownList ddGroup02 = (DropDownList)e.Row.FindControl("ddGroup02");
                ddGroup02.DataTextField = "association";
                ddGroup02.DataValueField = "association";
                ddGroup02.DataSource = load_group();
                ddGroup02.DataBind();
                ddGroup02.Items.Insert(0, new ListItem());

                DropDownList ddGroup03 = (DropDownList)e.Row.FindControl("ddGroup03");
                ddGroup03.DataTextField = "association";
                ddGroup03.DataValueField = "association";
                ddGroup03.DataSource = load_group();
                ddGroup03.DataBind();
                ddGroup03.Items.Insert(0, new ListItem());

                DropDownList ddGroup04 = (DropDownList)e.Row.FindControl("ddGroup04");
                ddGroup04.DataTextField = "association";
                ddGroup04.DataValueField = "association";
                ddGroup04.DataSource = load_group();
                ddGroup04.DataBind();
                ddGroup04.Items.Insert(0, new ListItem());

                DropDownList ddGroup05 = (DropDownList)e.Row.FindControl("ddGroup05");
                ddGroup05.DataTextField = "association";
                ddGroup05.DataValueField = "association";
                ddGroup05.DataSource = load_group();
                ddGroup05.DataBind();
                ddGroup05.Items.Insert(0, new ListItem());

                ddGroup01.SelectedValue = DataBinder.Eval(e.Row.DataItem, "group01").ToString();
                ddGroup02.SelectedValue = DataBinder.Eval(e.Row.DataItem, "group02").ToString();
                ddGroup03.SelectedValue = DataBinder.Eval(e.Row.DataItem, "group03").ToString();
                ddGroup04.SelectedValue = DataBinder.Eval(e.Row.DataItem, "group04").ToString();
                ddGroup05.SelectedValue = DataBinder.Eval(e.Row.DataItem, "group05").ToString();

                CheckBox cbAdmin = (CheckBox)e.Row.FindControl("cbAdmin");

                DataRowView dr = e.Row.DataItem as DataRowView;
                if (Convert.ToBoolean(dr["admin"] = true))
                {
                    cbAdmin.Checked = true;
                }
                else
                {
                    cbAdmin.Checked = false;
                }

            }
        }
    }
}

protected void val_sameDropDown_ServerValidate(object source, ServerValidateEventArgs args)
{
    args.IsValid = !haveSameValue(ddGroup01.SelectedValue, ddGroup02.SelectedValue) &&
                   !haveSameValue(ddGroup01.SelectedValue, ddGroup03.SelectedValue) &&
                   !haveSameValue(ddGroup01.SelectedValue, ddGroup04.SelectedValue) &&
                   !haveSameValue(ddGroup01.SelectedValue, ddGroup05.SelectedValue) &&
                   !haveSameValue(ddGroup02.SelectedValue, ddGroup03.SelectedValue) &&
                   !haveSameValue(ddGroup02.SelectedValue, ddGroup04.SelectedValue) &&
                   !haveSameValue(ddGroup02.SelectedValue, ddGroup05.SelectedValue) &&
                   !haveSameValue(ddGroup03.SelectedValue, ddGroup04.SelectedValue) &&
                   !haveSameValue(ddGroup03.SelectedValue, ddGroup05.SelectedValue) &&
                   !haveSameValue(ddGroup04.SelectedValue, ddGroup05.SelectedValue);
}
protected bool haveSameValue(string first, string second)
{
    if (!string.IsNullOrEmpty(first) & !string.IsNullOrEmpty(second) && first.Equals(second))
    {
        return first.Equals(second);
    }
    return first == null && second == null;
}

Thanks guys and gals. Look forward to the responses (love learning this stuff)

Cheers,

Trent

  • 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-06-17T17:22:51+00:00Added an answer on June 17, 2026 at 5:22 pm

    Since you will not have access to the edititem template in the scope of your validation method ,you have to do some bit of digging to locate the individual dropdowns.The EditIndex property of your grid view fortunately helps you to locate the controls painlessly.You should then do something like this

    Markup

    <asp:TemplateField HeaderText="Group 01">
                <ItemTemplate>
                    <asp:Label ID="lbGroup01" runat="server" Text='<%# Eval("group01") %>' ></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:DropDownList ID="ddGroup01" runat="server"></asp:DropDownList>
                    <asp:RequiredFieldValidator ID="valddGroup01" runat="server" ErrorMessage="Group 01 is required." CssClass="password_red_fail"  OnServerValidate="val_sameDropDown_ServerValidate" ControlToValidate="ddGroup01" Display="None" ></asp:RequiredFieldValidator>
                </EditItemTemplate>
            </asp:TemplateField>
    

    Code Behind

      protected void val_sameDropDown_ServerValidate(object source, ServerValidateEventArgs args)
    {
    DropDownlist ddGroup01 = (DropDownList)YourGridView.Rows(YourGridView.EditIndex).FindControl("ddGroup01");
    //Now you can use the selected value as you wish.
    
    }
    

    Let me know if this works.

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

Sidebar

Related Questions

Hopefully this question isn't as subjective as I think it may be. I have
Hopefully I can explain this clearly enough. I have a table that displays some
Hopefully this isn't a stupid question but I can't seem to work out how
First off I'm not sure that's the proper title for this question but hopefully
Hopefully this is a really quick one ;) I have written a lexer /
Hopefully this is an easy one... I have an NSObject with methods that is
Hopefully this is simple: I have a relatively long list where each list item
hopefully this will be an easy answer for some of you CSS veterans out
Hopefully this is less complex than I think. I have one table of companies,
Hopefully this is an easy/dumb question. I am redirecting program input and output 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.