DATAGRID SETTING VISIBILITY of CONTROLS on RUN TIME.

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default DATAGRID SETTING VISIBILITY of CONTROLS on RUN TIME.

    Dear ALL,
    I am facing a bit problem in DATAGRID. so may be you guys can help me
    out.
    Actually on a DataGrid I am having following controls:
    1) 2 DropDown Menu
    2) 1 Text Box
    3) 1 ADD Button
    4) 1 Remove Button

    So these all controls are in 1 row and looks like:

    DROPDOWN1 DROPDOWN2 TEXTBOX ADD BUTTON REMOVE BUTTON.

    So when user will press ADD Button then the same new row will be
    populated and will look like.

    DROPDOWN1 DROPDOWN2 TEXTBOX ADD BUTTON REMOVE BUTTON
    (ROW1)
    DROPDOWN1 DROPDOWN2 TEXTBOX ADD BUTTON REMOVE BUTTON
    (ROW2)

    And So on. So these rows will be populated until user press ADD BUTTON.
    and similarly on pressing the REMOVE BUTTON the corresponding ROW will
    be deleted.

    I have implemented this functionality. but NOW the REAL PROBLEM comes
    into picture.

    Actually, when this SECOND ROW (ROW 2 and so on) will be populated
    then I have to set the VISIBILITY of ADD BUTTON of FIRST ROW (or
    previous row) to FALSE.

    SO LOGICALLY SPEAKING this ADD Button should be visible only for the
    CURRENT ROW and for all the previous rows the ADD BUTTON's TEXT should
    be replaced by a LABEL Control.

    I tried to access this BUTTON CONTROL a lot but was unable to do that.

    So if you have any idea then please let me know. I am posting the code
    for your review. Your help is really appreciated.


    public void Page_Load(object sender, System.EventArgs e)
    {
    if (!IsPostBack)
    {
    dsSource.Tables.Add(new DataTable("RepeaterSource"));
    dsSource.Tables[0].Columns.Add(new
    DataColumn("DropDownValue2"));
    dsSource.Tables[0].Columns.Add(new DataColumn("EditBoxValue"));
    dsSource.Tables[0].Rows.Add(new Object[] { 2,""});
    datagrid1.DataSource = dsSource;
    datagrid1.DataMember = "RepeaterSource";
    datagrid1.DataBind();

    Session[DATA_SOURCE_KEY] = dsSource;
    }
    else
    {
    dsSource = (DataSet)Session[DATA_SOURCE_KEY];
    datagrid1.DataSource = dsSource;
    datagrid1.DataMember = "RepeaterSource";
    }
    }

    public void OnItemCommand(Object sender, DataGridCommandEventArgs e)
    {
    Label lLabel = new Label();
    if(e.CommandName == "Add")
    dsSource.Tables[0].Rows.Add(new object[] {1,"Text Here" });
    dsSource.Tables[0].Rows[e.Item.ItemIndex-1][3].ToString =
    "tEXT";
    datagrid1.DataBind();
    Session[DATA_SOURCE_KEY] = dsSource;
    }
    if(e.CommandName =="Delete")
    {
    dsSource.Tables[0].Rows[e.Item.ItemIndex].Delete();
    datagrid1.DataBind();
    Session[DATA_SOURCE_KEY] = dsSource;
    }
    }




    HERE IS THE CODE BEHIND PAGE:`
    <asp:datagrid id="datagrid1" runat="server" Width="288px"
    GridLines="Vertical" Font-Size="8pt"
    Font-Name="verdana" Cellpadding="3" AutoGenerateColumns="False"
    ShowFooter="True" BorderWidth="1px" BorderColor="#999999"
    BackColor="White" Font-Names="verdana" BorderStyle="None"
    OnItemCommand="OnItemCommand"
    <Columns>
    <asp:TemplateColumn>
    <ItemTemplate>
    ` <asp:DropDownList Runat="server"
    ID="comparatorDropDown" >
    <asp:ListItem Value="2" Text="Select Comparator"
    lected="True"></asp:ListItem>
    </asp:DropDownList>
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:DropDownList id="Dropdownlist1"
    runat="server" >
    <asp:ListItem
    Value="citigroup_cfo">CitiGroup_Cfo</asp:ListItem>
    <asp:ListItem
    Value="citigroup_cf1">CitiGroup_Cf1</asp:ListItem>
    </asp:DropDownList>
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:TextBox id="Textbox1" runat="server"
    Columns="20" />
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:Label Runat="server" ID="Label1"
    Visible="true">AND</asp:Label
    </ItemTemplate>
    <FooterTemplate>
    <asp:Button Text="Add Condition" Font-Size="10px"
    runat="server"
    ID="AddButton" CommandName="Add" Width="100%" />
    </FooterTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:Button runat="Server" Text="Remove
    Condition"
    ID="RemoveButton" CommandName="Delete" Width="100%" Font-Size="10px" />
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:datagrid>

    Rocky Guest

  2. Similar Questions and Discussions

    1. datagrid on a panel that has visibility set to false
      Man this is annoying. I have a datagrid on a panel. The panel has ..Visible=False. I did not specify the datagrid's visible property. Now it...
    2. Control.Controls bug? Control's child controls missing at the run time.
      Hello, ..NET 1.1/VB.NET: I have a custom web control Public Class DatePicker Inherits Control Implements INamingContainer
    3. Setting default playback controls
      I was wondering if there is anyway to set the default playback controls for captivate. (i.e. I would like the Halo playback control to be the...
    4. Setting up secure custom Web Controls
      I've read through "Building Secure MS ASP.NET Applications", and "Improving Web Application Security", but I'm a little confused about how to...
  3. #2

    Default DATAGRID SETTING VISIBILITY of CONTROLS on RUN TIME.

    Dear ALL,
    I am facing a bit problem in DATAGRID. so may be you guys can help me
    out.
    Actually on a DataGrid I am having following controls:
    1) 2 DropDown Menu
    2) 1 Text Box
    3) 1 ADD Button
    4) 1 Remove Button

    So these all controls are in 1 row and looks like:

    DROPDOWN1 DROPDOWN2 TEXTBOX ADD BUTTON REMOVE BUTTON.

    So when user will press ADD Button then the same new row will be
    populated and will look like.

    DROPDOWN1 DROPDOWN2 TEXTBOX ADD BUTTON REMOVE BUTTON
    (ROW1)
    DROPDOWN1 DROPDOWN2 TEXTBOX ADD BUTTON REMOVE BUTTON
    (ROW2)

    And So on. So these rows will be populated until user press ADD BUTTON.
    and similarly on pressing the REMOVE BUTTON the corresponding ROW will
    be deleted.

    I have implemented this functionality. but NOW the REAL PROBLEM comes
    into picture.

    Actually, when this SECOND ROW (ROW 2 and so on) will be populated
    then I have to set the VISIBILITY of ADD BUTTON of FIRST ROW (or
    previous row) to FALSE.

    SO LOGICALLY SPEAKING this ADD Button should be visible only for the
    CURRENT ROW and for all the previous rows the ADD BUTTON's TEXT should
    be replaced by a LABEL Control.

    I tried to access this BUTTON CONTROL a lot but was unable to do that.

    So if you have any idea then please let me know. I am posting the code
    for your review. Your help is really appreciated.


    public void Page_Load(object sender, System.EventArgs e)
    {
    if (!IsPostBack)
    {
    dsSource.Tables.Add(new DataTable("RepeaterSource"));
    dsSource.Tables[0].Columns.Add(new
    DataColumn("DropDownValue2"));
    dsSource.Tables[0].Columns.Add(new DataColumn("EditBoxValue"));
    dsSource.Tables[0].Rows.Add(new Object[] { 2,""});
    datagrid1.DataSource = dsSource;
    datagrid1.DataMember = "RepeaterSource";
    datagrid1.DataBind();

    Session[DATA_SOURCE_KEY] = dsSource;
    }
    else
    {
    dsSource = (DataSet)Session[DATA_SOURCE_KEY];
    datagrid1.DataSource = dsSource;
    datagrid1.DataMember = "RepeaterSource";
    }
    }

    public void OnItemCommand(Object sender, DataGridCommandEventArgs e)
    {
    Label lLabel = new Label();
    if(e.CommandName == "Add")
    dsSource.Tables[0].Rows.Add(new object[] {1,"Text Here" });
    dsSource.Tables[0].Rows[e.Item.ItemIndex-1][3].ToString =
    "tEXT";
    datagrid1.DataBind();
    Session[DATA_SOURCE_KEY] = dsSource;
    }
    if(e.CommandName =="Delete")
    {
    dsSource.Tables[0].Rows[e.Item.ItemIndex].Delete();
    datagrid1.DataBind();
    Session[DATA_SOURCE_KEY] = dsSource;
    }
    }




    HERE IS THE CODE BEHIND PAGE:`
    <asp:datagrid id="datagrid1" runat="server" Width="288px"
    GridLines="Vertical" Font-Size="8pt"
    Font-Name="verdana" Cellpadding="3" AutoGenerateColumns="False"
    ShowFooter="True" BorderWidth="1px" BorderColor="#999999"
    BackColor="White" Font-Names="verdana" BorderStyle="None"
    OnItemCommand="OnItemCommand"
    <Columns>
    <asp:TemplateColumn>
    <ItemTemplate>
    ` <asp:DropDownList Runat="server"
    ID="comparatorDropDown" >
    <asp:ListItem Value="2" Text="Select Comparator"
    lected="True"></asp:ListItem>
    </asp:DropDownList>
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:DropDownList id="Dropdownlist1"
    runat="server" >
    <asp:ListItem
    Value="citigroup_cfo">CitiGroup_Cfo</asp:ListItem>
    <asp:ListItem
    Value="citigroup_cf1">CitiGroup_Cf1</asp:ListItem>
    </asp:DropDownList>
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:TextBox id="Textbox1" runat="server"
    Columns="20" />
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:Label Runat="server" ID="Label1"
    Visible="true">AND</asp:Label
    </ItemTemplate>
    <FooterTemplate>
    <asp:Button Text="Add Condition" Font-Size="10px"
    runat="server"
    ID="AddButton" CommandName="Add" Width="100%" />
    </FooterTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:Button runat="Server" Text="Remove
    Condition"
    ID="RemoveButton" CommandName="Delete" Width="100%" Font-Size="10px" />
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:datagrid>

    Rocky Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139