DATAGRID SETTING VISIBILITY of CONTROLS on RUN TIME.

R

Rocky

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top