Ask a Question related to ASP.NET Building Controls, Design and Development.
-
Rocky #1
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
-
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... -
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 -
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... -
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... -
Formatting a time field to 24 hour time (Military time) in the Datagrid
Anyone know how to do this? -
Rocky #2
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



Reply With Quote

