Rahul Parashar

Rahul Parashar

  • NA
  • 15
  • 3.3k

Generic grid Need help

Jun 16 2015 7:13 AM
hello,Everyone
In my Project I have requirement of generic grid view .where I cant use In built server side Controls.
I have made grid view and all its template text box and bound field with help of c# and there
Is requirement ,On the selected index change of Drop down List the grid will generates the no
of columns which has template fields containing text box.if select 3 in specific rows drop down
then 3 columns comes at that row of grid view.
 
so ,please share your suggestion and ideas to help me out.
 
I will highly thank full of yours
  
 ----------------------------------------------------------------------------------------------------------------------------------
please check the attached folder below there will form two form 1.demo,2.ddlldynamic.
I want demo functionality of ddl in ddldynamic grid containing inside the grid  nt able to achive that functionallity.
 
 
--------------------------------------------------------------------
 
 
<asp:GridView ID="GV" runat="server" BackColor="#DEBA84" BorderColor="#999999"
BorderStyle="None" BorderWidth="1px"
CellPadding="3" GridLines="Vertical" Height="34px" Width="100%"
Font-Names="Arial" Font-Size="Small" AutoGenerateColumns="False"
onrowcommand="GV_RowCommand">
<HeaderStyle Font-Size="10px" CssClass="gridheadercolor" Font-Bold="True" ForeColor="White" />
<RowStyle CssClass="GridRow" />
<AlternatingRowStyle BackColor="#D6E9F0"/>
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:Label ID="lblSubExpense" runat="server" Text="Sub Expense"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblSubExpense" runat="server" Text='<%# Eval("Sub Expense") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField >
<HeaderTemplate>
<asp:Label ID="lblbudgetamt" runat="server" Text="Budget Amount" CssClass="LabelCss"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="Txtbudgetamt" Width="50px" runat="server" CssClass="LabelCss"> </asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField >
<HeaderTemplate >
<asp:Label ID="lblMoniteringPeriod" runat="server" Text="Monitering Period" CssClass="LabelCss"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:DropDownList ID="ddlbudgetprd" runat="server" CssClass="LabelCss" Width="100px"
AutoPostBack="True" onselectedindexchanged="ddlbudgetprd_SelectedIndexChanged"
>
<asp:ListItem Value="0">Select Period</asp:ListItem>
<asp:ListItem Value="1">Monthly</asp:ListItem>
<asp:ListItem Value="2">Quaterly</asp:ListItem>
<asp:ListItem Value="3">Half-yearly</asp:ListItem>
<asp:ListItem Value="4">Annualy</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField >
<HeaderTemplate>
<asp:Label ID="lblForwardRemainingBalance" CssClass="LabelCss" runat="server" Text="Forward Remaining Balance"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:RadioButtonList ID="rdobalancestatus" runat="server" CssClass="LabelCss"
RepeatDirection="Horizontal">
<asp:ListItem Selected="True" Value="Yes">Yes</asp:ListItem>
<asp:ListItem Value="No">No</asp:ListItem>
</asp:RadioButtonList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="1" Visible="false" >
<ItemTemplate>
<asp:TextBox ID="Txtbudgetamt1" Width="50px" runat="server"> </asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="2" Visible="false" >
<ItemTemplate>
<asp:TextBox ID="Txtbudgetamt2" Width="50px" runat="server"> </asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="3" Visible="false">
<ItemTemplate>
<asp:TextBox ID="Txtbudgetamt3" Width="50px" runat="server"> </asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="4" Visible="false">
<ItemTemplate>
<asp:TextBox ID="Txtbudgetamt4" Width="50px" runat="server"> </asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="5" Visible="false">
<ItemTemplate>
<asp:TextBox ID="Txtbudgetamt5" Width="50px" runat="server"> </asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="6" Visible="false">
<ItemTemplate>
<asp:TextBox ID="Txtbudgetamt6" Width="50px" runat="server"> </asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="7" Visible="false">
<ItemTemplate>
<asp:TextBox ID="Txtbudgetamt7" Width="50px" runat="server"> </asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="8" Visible="false">
<ItemTemplate>
<asp:TextBox ID="Txtbudgetamt8" Width="50px" runat="server"> </asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="9" Visible="false">
<ItemTemplate>
<asp:TextBox ID="Txtbudgetamt9" Width="50px" runat="server"> </asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="10" Visible="false" >
<ItemTemplate>
<asp:TextBox ID="Txtbudgetamt10" Width="50px" runat="server"> </asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="11" Visible="false">
<ItemTemplate>
<asp:TextBox ID="Txtbudgetamt11" Width="50px" runat="server"> </asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="12" Visible="false">
<ItemTemplate>
<asp:TextBox ID="Txtbudgetamt12" Width="50px" runat="server"> </asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataRowStyle BackColor="#D6E9F0" Font-Bold="True" Font-Size="Large"
Font-Underline="True" />
<FooterStyle BackColor="#D6E9F0" />
<HeaderStyle CssClass="gridheadercolor" Horizontal />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<RowStyle BackColor="#ABD2E1" ForeColor="Black" />
<SelectedRowStyle CssClass=" rowcolor" Font-Bold="True" ForeColor="White" />
</asp:GridView>
 
 
 
 
 
 
 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
int j = 0;
int k;
DropDownList ddlbudgetprd = (DropDownList)sender;
GridViewRow GVR = ((GridViewRow)ddlbudgetprd.Parent.Parent);
k = GVR.RowIndex;
if (GVR != null)
{
DropDownList lbName = GVR.FindControl("ddlbudgetprd") as DropDownList;
ddlbudgetprd = lbName;
}
j = Convert.ToInt32(ddlbudgetprd.SelectedValue);
//DropDownList dl = (DropDownList)GV.Rows[k].Cells[2].FindControl("ddlbudgetprd");
//j = Convert.ToInt32(dl.SelectedValue);
TextBox tx1 = (TextBox)GV.Rows[k].Cells[4].FindControl("Txtbudgetamt1");
TextBox tx2 = (TextBox)GV.Rows[k].Cells[5].FindControl("Txtbudgetamt2");
TextBox tx3 = (TextBox)GV.Rows[k].Cells[6].FindControl("Txtbudgetamt3");
TextBox tx4 = (TextBox)GV.Rows[k].Cells[7].FindControl("Txtbudgetamt4");
TextBox tx5 = (TextBox)GV.Rows[k].Cells[8].FindControl("Txtbudgetamt5");
TextBox tx6 = (TextBox)GV.Rows[k].Cells[9].FindControl("Txtbudgetamt6");
TextBox tx7 = (TextBox)GV.Rows[k].Cells[10].FindControl("Txtbudgetamt7");
TextBox tx8 = (TextBox)GV.Rows[k].Cells[11].FindControl("Txtbudgetamt8");
TextBox tx9 = (TextBox)GV.Rows[k].Cells[12].FindControl("Txtbudgetamt9");
TextBox tx10 = (TextBox)GV.Rows[k].Cells[13].FindControl("Txtbudgetamt10");
TextBox tx11 = (TextBox)GV.Rows[k].Cells[14].FindControl("Txtbudgetamt11");
TextBox tx12 = (TextBox)GV.Rows[k].Cells[15].FindControl("Txtbudgetamt12");
if (j == 1)
{
GV.Rows[k].Cells[4].Visible.Equals(true);
tx1.Visible = true;
GV.Rows[k].Cells[5].Visible.Equals(false);
tx2.Visible = false;
GV.Rows[k].Cells[6].Visible.Equals(false);
tx3.Visible = false;
GV.Rows[k].Cells[7].Visible.Equals(false);
tx4.Visible = false;
GV.Rows[k].Cells[8].Visible.Equals(false);
tx5.Visible = false;
GV.Rows[k].Cells[9].Visible.Equals(false);
tx6.Visible = false;
GV.Rows[k].Cells[10].Visible.Equals(false);
tx7.Visible = false;
GV.Rows[k].Cells[11].Visible.Equals(false);
tx8.Visible = false;
GV.Rows[k].Cells[12].Visible.Equals(false);
tx9.Visible = false;
GV.Rows[k].Cells[13].Visible.Equals(false);
tx10.Visible = false;
GV.Rows[k].Cells[14].Visible.Equals(false);
tx11.Visible = false;
GV.Rows[k].Cells[15].Visible.Equals(false);
tx12.Visible = false;
}
if (j ==2)
{
GV.Rows[k].Cells[4].Visible.Equals(true);
tx1.Visible = true;
GV.Rows[k].Cells[5].Visible.Equals(true);
tx2.Visible = true;
GV.Rows[k].Cells[6].Visible.Equals(true);
tx3.Visible = true;
GV.Rows[k].Cells[7].Visible.Equals(false);
tx4.Visible = false;
GV.Rows[k].Cells[8].Visible.Equals(false);
tx5.Visible = false;
GV.Rows[k].Cells[9].Visible.Equals(false);
tx6.Visible = false;
GV.Rows[k].Cells[10].Visible.Equals(false);
tx7.Visible = false;
GV.Rows[k].Cells[11].Visible.Equals(false);
tx8.Visible = false;
GV.Rows[k].Cells[12].Visible.Equals(false);
tx9.Visible = false;
GV.Rows[k].Cells[13].Visible.Equals(false);
tx10.Visible = false;
GV.Rows[k].Cells[14].Visible.Equals(false);
tx11.Visible = false;
GV.Rows[k].Cells[15].Visible.Equals(false);
tx12.Visible = false;
}
else if (j == 3)
{
GV.Rows[k].Cells[4].Visible.Equals(true);
tx1.Visible = true;
GV.Rows[k].Cells[5].Visible.Equals(true);
tx2.Visible = true;
GV.Rows[k].Cells[6].Visible.Equals(true);
tx3.Visible = true;
GV.Rows[k].Cells[7].Visible.Equals(true);
tx4.Visible = true;
GV.Rows[k].Cells[8].Visible.Equals(true);
tx5.Visible = true;
GV.Rows[k].Cells[9].Visible.Equals(true);
tx6.Visible = true;
GV.Rows[k].Cells[10].Visible.Equals(false);
tx7.Visible = false;
GV.Rows[k].Cells[11].Visible.Equals(false);
tx8.Visible = false;
GV.Rows[k].Cells[12].Visible.Equals(false);
tx9.Visible = false;
GV.Rows[k].Cells[13].Visible.Equals(false);
tx10.Visible = false;
GV.Rows[k].Cells[14].Visible.Equals(false);
tx11.Visible = false;
GV.Rows[k].Cells[15].Visible.Equals(false);
tx12.Visible = false;
}
else if (j == 4)
{
GV.Rows[k].Cells[4].Visible.Equals(true);
tx1.Visible = true;
GV.Rows[k].Cells[5].Visible.Equals(true);
tx2.Visible = true;
GV.Rows[k].Cells[6].Visible.Equals(true);
tx3.Visible = true;
GV.Rows[k].Cells[7].Visible.Equals(true);
tx4.Visible = true;
GV.Rows[k].Cells[8].Visible.Equals(true);
tx5.Visible = true;
GV.Rows[k].Cells[9].Visible.Equals(true);
tx6.Visible = true;
GV.Rows[k].Cells[10].Visible.Equals(true);
tx7.Visible = true;
GV.Rows[k].Cells[11].Visible.Equals(true);
tx8.Visible = true;
GV.Rows[k].Cells[12].Visible.Equals(true);
tx9.Visible = true;
GV.Rows[k].Cells[13].Visible.Equals(true);
tx10.Visible = true;
GV.Rows[k].Cells[14].Visible.Equals(true);
tx11.Visible = true;
GV.Rows[k].Cells[15].Visible.Equals(true);
tx12.Visible = true;
}
 

Attachment: website2.zip