Link to home
Start Free TrialLog in
Avatar of Ali Shah
Ali ShahFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How to validate control in asp.net GridView which is doing bulk update

Hi guys,

I have got a gridview which has got a dropdownlist and a textbox. At the moment i can select the value from the dropdown list but can leave the textbox blank. I want to add the functionality that if i select the value from the dropdown list then the textbox becomes required in that particular row of the gridview.

I am using the following the http://msdn.microsoft.com/en-us/library/aa992036(v=vs.80).aspx tutorial from microsoft to perform the bulkupdate.

can i add the above functionality with the bulk update?

any help would be highly appreciated

regards
Ali
ASKER CERTIFIED SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ali Shah

ASKER

Hi Mas,

thanks for the reply, your suggestions work well with the single update for a single control but i want something for gridview bulkupdate.  i suppose i need to itereate through each control of the gridview to implement this. But as i am quite new in .Net programming so i couldn't figure out how to achieve this.

regards
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks again for reply, and sorry to be a pain but it woud be really great if you could give me the start point.

Below is the code for my dropdownlist itemtemplate

                <ItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True"
                        SelectedValue='<%# Bind("Actual") %>'>
                               <asp:ListItem Text ="--" Value =""></asp:ListItem>
                        <asp:ListItem>1</asp:ListItem>
                        <asp:ListItem>2</asp:ListItem>
                        <asp:ListItem>3</asp:ListItem>
                        <asp:ListItem>4</asp:ListItem>
                        <asp:ListItem>5</asp:ListItem>
                    </asp:DropDownList>
                   
                </ItemTemplate>

When i run the page the initial text of the dropdown is "--" and it's value is "". Now i want that if i select the value other than "" then the txtbox should be enabled otherwise it is disabled. Now i have tried the following code

 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList drp = GrdRisks.FindControl("DropDownList1") as DropDownList;
            TextBox txt = GrdRisks.FindControl("TextBox2") as TextBox;

            if (drp.SelectedValue != "")
            {
                txt.Enabled = true;
            }
            else
            {
                txt.Text = "";
                txt.Enabled = false;
            }
        }

but it gave me the following error when i tried changing the selected value

"NULLReference exception was unhandled by usercode"
"Object reference not set to an instance of object"

thanks
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you so much for your great help. This is working fine i need a bit more help from you guys and i have asked another question in the forum  https://www.experts-exchange.com/questions/27746876/How-to-Make-the-text-field-of-a-gridview-required-depending-on-the-selected-value-of-dropdown-control-of-the-same-gridview.html
looking forward for the help again.

kind regards,
ALi