Hi All
I am developing a web appln using VS 2005(using C# as a language) and SQL Server 2005. I have a gridview in my page with add, edit , delete,update button in it. In the footer row i have a dropdown with the following list items: Self, Mother, Father,Spouse,Daughter and Son. Only son and daughter can be selected more than once here. On Clicking on add, i am saving values into viewstate, same for edit/update/delete. only on clicking on submit button, i am inserting into database.
I want to give an alert to the user if the grid contains rows with multiple Self,Mother,Father and Spouse.
There is a submit button outside the grid and on this event i wanna restrict user.
Code:
protectedvoid btnSubmit_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in gridRelation.Rows)
{
/// code needed
}
}
design page code:
Code:
<asp:GridViewID="gridRelation"Width="100%"CellPadding="2"CellSpacing="1"BorderWidth="0"BackColor="#c1c1c1"
runat="server"AutoGenerateColumns="false"
ShowFooter="true"CssClass="textbox"FooterStyle-BackColor="#ffffff"HeaderStyle-BackColor="#e1e1e1"
AllowPaging="false"PageSize="10"EmptyDataRowStyle-ForeColor="Red"
OnRowCommand="gridRelation_RowCommand"
OnRowDataBound="gridRelation_RowDataBound"
OnRowDeleting="gridRelation_RowDeleting"
OnRowUpdating="gridRelation_RowUpdating"
OnRowEditing="gridRelation_RowEditing"
OnRowCancelingEdit="gridRelation_RowCancelingEdit">
<Columns>
<asp:TemplateFieldAccessibleHeaderText="SlNo"HeaderText="SlNo"HeaderStyle-HorizontalAlign="center">
<ItemStyleHorizontalAlign="center"BackColor="#ffffff"/>
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
<FooterTemplate>
<asp:HiddenFieldID="hfSlno"runat="server"Value="0"/>
</FooterTemplate>
<FooterStyleHorizontalAlign="center"BackColor="#ffffff"/>
<HeaderStyleBackColor="#e1e1e1"/>
</asp:TemplateField>
<asp:TemplateFieldAccessibleHeaderText="Relation"HeaderText="Relation"HeaderStyle-HorizontalAlign="center">
<ItemStyleHorizontalAlign="center"BackColor="#ffffff"/><ItemTemplate>
<asp:LabelID="lblRelation"runat="server"Text='<%# DataBinder.Eval(Container.DataItem, "RelationType")%>'/>
</ItemTemplate>
<HeaderStyleBackColor="#e1e1e1"/>
<EditItemTemplate>
<asp:DropDownListID="ddlERelation"runat="server"CssClass="textbox">
<asp:ListItemText="Select"Value="Select"></asp:ListItem>
<asp:ListItemText="Self"Value="Self"></asp:ListItem>
<asp:ListItemText="Mother"Value="Mother"></asp:ListItem>
<asp:ListItemText="Father"Value="Father"></asp:ListItem>
<asp:ListItemText="Spouse"Value="Spouse"></asp:ListItem>
<asp:ListItemText="Daughter"Value="Daughter"></asp:ListItem>
<asp:ListItemText="Son"Value="Son"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownListID="ddlFRelation"runat="server"CssClass="textbox">
<asp:ListItemText="Select"Value="Select"></asp:ListItem>
<asp:ListItemText="Self"Value="Self"></asp:ListItem>
<asp:ListItemText="Mother"Value="Mother"></asp:ListItem>
<asp:ListItemText="Father"Value="Father"></asp:ListItem>
<asp:ListItemText="Spouse"Value="Spouse"></asp:ListItem>
<asp:ListItemText="Daughter"Value="Daughter"></asp:ListItem>
<asp:ListItemText="Son"Value="Son"></asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
<HeaderStyleBackColor="#e1e1e1"/>
<ItemStyle/>
<FooterStyleHorizontalAlign="center"BackColor="#ffffff"/>
</asp:TemplateField>
<asp:TemplateFieldAccessibleHeaderText="Name"HeaderText="Name"HeaderStyle-HorizontalAlign="center">
<ItemStyleHorizontalAlign="center"BackColor="#ffffff"/><ItemTemplate>
<%#DataBinder.Eval(Container.DataItem, "Name")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBoxID="txtEName"MaxLength="30"runat="server"CssClass="textbox"Text='<%# Bind("Name") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBoxID="txtFName"runat="server"CssClass="textbox"MaxLength="30"></asp:TextBox></FooterTemplate>
<HeaderStyleBackColor="#e1e1e1"/>
<ItemStyle/>
<FooterStyleHorizontalAlign="center"BackColor="#ffffff"/>
</asp:TemplateField>
<asp:TemplateFieldHeaderStyle-Width="15%">
<ItemStyleBackColor="#ffffff"/>
<EditItemTemplate><asp:ButtonID="bttUpdate"runat="server"CssClass="textboxandbutt"CommandName="Update"Text="Update"/>
<asp:ButtonID="bttCancel"runat="server"CssClass="textboxandbutt"CommandName="Cancel"Text="Cancel"/>
</EditItemTemplate>
<ItemTemplate>
<asp:ButtonID="bttEdit"runat="server"CssClass="textboxandbutt"CommandName="Edit"Text="Edit"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateFieldHeaderStyle-Width="10%">
<ItemStyleBackColor="#ffffff"/>
<ItemTemplate>
<asp:ButtonID="bttDel"runat="server"CssClass="textboxandbutt"CommandName="Delete"Text="Delete"/>
</ItemTemplate>
<FooterTemplate>
<asp:ButtonID="bttAdd"runat="server"CssClass="textboxandbutt"CommandName="Add"Text="Add"/>
</FooterTemplate>
<FooterStyleBackColor="#FFFFFF"/>
</asp:TemplateField>
</Columns>
</asp:GridView>
how to handle this? Please throw light....
How to count the number of rows in gridview that contains a specific text. In My Gridview values are binded into label, this can be clearly seen from the code.
-- Abhishek