Dynamic Loading of validation Controls

kunal.kb

Member
Joined
Sep 8, 2005
Messages
21
Programming Experience
Beginner
i have a datagrid..which is editable...
there is an Edit button.When i click that button the columns of the datagrid are transformed into textboxes...
now i want to add RequiredFieldValidator for those text boxes....
i don't know how to do it....
please help me.....
 

onepieceking

Well-known member
Joined
Sep 20, 2006
Messages
64
Programming Experience
1-3
Hi,

Code:
<asp:datagrid id....>
    <ItemStyle ....></ItemStyle>
    <HeaderStyle ....></HeaderStyle>
    <Columns>
        <asp:EditCommandColumn .....>
        </asp:EditCommandColumn>
 
        <asp:TemplateColumn .....>
            <ItemTemplate>
                <asp:Label ......></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
                <asp:TextBox ..........>
                    [COLOR=red]<asp:RequireFieldValidator.......... />[/COLOR]
                </asp:TextBox>
            <EditItemTemplate>
         </asp:TemplateColumn>
    </Columns>
</asp:datagrid>
You have to edit the datagrid yourself. From the above code, there will be 2 columns (one for "edit" and one for showing). As you can see, the TemplateColumn will have 2 things, ItemTemplate and EditTemplate.

When the datagrid is loaded, the ltemTemplate will show the label. When you click the "edit", the EditItemTemplate will show the textbox.

For more info, search for TemplateColumn, ItemTemplate and EditItemTemplate in MSDN.
 
Top Bottom