Ali Shah
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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:ListI tem>
<asp:ListItem>2</asp:ListI tem>
<asp:ListItem>3</asp:ListI tem>
<asp:ListItem>4</asp:ListI tem>
<asp:ListItem>5</asp:ListI tem>
</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_SelectedInde xChanged(o bject sender, EventArgs e)
{
DropDownList drp = GrdRisks.FindControl("Drop DownList1" ) as DropDownList;
TextBox txt = GrdRisks.FindControl("Text Box2") 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
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:ListI
<asp:ListItem>2</asp:ListI
<asp:ListItem>3</asp:ListI
<asp:ListItem>4</asp:ListI
<asp:ListItem>5</asp:ListI
</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_SelectedInde
{
DropDownList drp = GrdRisks.FindControl("Drop
TextBox txt = GrdRisks.FindControl("Text
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
looking forward for the help again.
kind regards,
ALi
ASKER
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