Solved

GridView Validation

Posted on 2008-06-11
3
765 Views
Last Modified: 2012-06-21
hi

I have a gridview with two columns that contain a textbox each that i would like to validate. Each row also contains an imagebutton that does some action. How do i make it so that it only validates for the specific row that the button was click?


Allan


<asp:GridView ID="gvPossibleAnswers" EnableViewState="true" AutoGenerateColumns="false" runat="server" OnRowCreated="gvPossibleAnswers_RowCreated" OnRowDataBound="gvPossibleAnswers_RowDataBound">
                        <Columns>
                            <asp:BoundField HeaderText="Option ID" DataField="OptionID" />
                            <asp:TemplateField HeaderText="Label Text">
                                <ItemTemplate>
                                    <asp:TextBox ID="txtOptionText" runat="server" Text=""></asp:TextBox>
                                    <asp:RequiredFieldValidator id="rfvOptionText" ControlToValidate="txtOptionText" ErrorMessage="Answer Text is missing" Display="none" runat="server"></asp:RequiredFieldValidator>                       
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Sort Order">
                                <ItemTemplate>
                                    <asp:TextBox ID="txtSortOrder" runat="server" Text=""></asp:TextBox>
                                    <asp:RegularExpressionValidator ID="revSortOrder" ControlToValidate="txtSortOrder" runat="server" ErrorMessage="Sort Order must be a digit" Display="none" ValidationExpression="^\d+$"></asp:RegularExpressionValidator>
                                </ItemTemplate>                        
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Status">
                                <ItemTemplate>
                                    <asp:DropDownList EnableViewState="true" ID="ddlStatusInd" runat="server">
                                        <asp:ListItem Value="0S1" Text="Active" />
                                        <asp:ListItem Value="0S0" Text="InActive" />
                                    </asp:DropDownList>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Actions">
                                <ItemTemplate>
                                    <asp:ImageButton ID="imgBtnAdd" runat="server" ImageUrl="~/Images/Delete.gif" OnClick="imgBtnAdd_Click" />
                                    <asp:ImageButton ID="imgBtnEdit" runat="server" ImageUrl="~/Images/Edit.gif" OnClick="imgBtnEdit_Click" />
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>

Open in new window

0
Comment
Question by:acadenilla
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
NazoUK earned 350 total points
ID: 21761455
Is OptionID a unique field for each row?

You could add a validationgroup to your validators and imagebutton, something like:

ValidationGroup = 'row<%#Eval("OptionID")'

This should create a unique validation group for each row and ensure the validators only act on the controls in their own row.
0
 

Author Closing Comment

by:acadenilla
ID: 31466168
thx nazouk

i got it work with your suggestion
0
 

Author Comment

by:acadenilla
ID: 21764086
Note i had to dynamically add ValidationSummary controls for each row in for the validation to show the error message.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question