its my code i want to hide div which have id selnumber (when i select form 60/61 and show a text message "It is form 60/61" at the place of div) but when select pan then show the div.
<div id="selpan">
<asp:DropDownList ID="ddlpan" runat="server">
<asp:ListItem>---Select---</asp:ListItem>
<asp:ListItem>PAN</asp:ListItem>
<asp:ListItem>FORM 60/61</asp:ListItem>
</asp:DropDownList> </div>
</td><div id="selnumber">
<td colspan="3">
<asp:Label ID="add_no" runat="server" Font-Bold="True" Font-Names="Verdana"
Font-Size="10pt" Font-Strikeout="False" Text="File Number"></asp:Label>
</td><td>
<asp:TextBox ID="tbnumber" runat="server" ontextchanged="tbnumber_TextChanged"></asp:TextBox>
</td>
</div>
you can add onchange event on dropdownlist and though javascript you can check if selected item in the list in form 60/61 then hide the div else show the div.
<div id="selpan">
<asp:DropDownList AutoPostBack="true" ID="ddlpan" runat="server" onselectedindexchanged="ddlpan_SelectedIndexChanged">
<asp:ListItem>---Select---</asp:ListItem>
<asp:ListItem>PAN</asp:ListItem>
<asp:ListItem>FORM 60/61</asp:ListItem>
</asp:DropDownList> </div>
<asp:Label Visible="false" ID="lblMessage" runat="server" Font-Bold="True" Font-Names="Verdana" Font-Size="10pt" Font-Strikeout="False" Text="File Number"></asp:Label>
<div id="selnumber" Visible="false" runat="server">
<asp:Label ID="add_no" runat="server" Font-Bold="True" Font-Names="Verdana" Font-Size="10pt" Font-Strikeout="False" Text="File Number"></asp:Label>
<asp:TextBox ID="tbnumber" runat="server" ontextchanged="tbnumber_TextChanged"></asp:TextBox>
</div>
.....
protected void ddlpan_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlpan.SelectedIndex == 1)
{
selnumber.Visible = true;
lblMessage.Visible = false;
}
else if (ddlpan.SelectedIndex == 2)
{
selnumber.Visible = false;
lblMessage.Visible = true;
lblMessage.Text = "It is form 60/61";
}
}
Two ways you can do this.
You can either use onSelectedIndexChanged() event like #Sruthi already said but that will include an unnecessary call to server and take time.
Second and better way to do this is to use javascript onchange() event and save both time and resources.
Javascript code.
<script type="text/javascript">
function change() {
var DropdownList = document.getElementById('<%=ddlpan.ClientID %>');
var SelectedIndex = DropdownList.selectedIndex;
var message = document.getElementById('message');
var selnumber = document.getElementById('selnumber');
if (SelectedIndex == 2) {
selnumber.style.display = "none";
message.style.display = "block";
}
else {
selnumber.style.display = "block";
message.style.display = "none";
}
}
</script>
ASP.NET code..
<div id="selpan">
<asp:DropDownList ID="ddlpan" runat="server" onchange="change()">
<asp:ListItem>---Select---</asp:ListItem>
<asp:ListItem>PAN</asp:ListItem>
<asp:ListItem>FORM 60/61</asp:ListItem>
</asp:DropDownList>
<asp:Label ID="label" runat="server"></asp:Label></div>
</td><div id="selnumber" style="">
<td colspan="3">
<asp:Label ID="add_no" runat="server" Font-Bold="True" Font-Names="Verdana"
Font-Size="10pt" Font-Strikeout="False" Text="File Number"></asp:Label>
</td><td>
<asp:TextBox ID="tbnumber" runat="server" ></asp:TextBox>
</td>
</div>
<div id="message" style="display:none">
<label>This is form 60/61</label>
</div>
Related
I want to set individual DIVs inside a grid visible/hidden programmatically like so, but it isn't working. How would you fix this code?
foreach (DataGridItem dgItem in dgW.Items)
{
HtmlGenericControl dvGoodRow =
(HtmlGenericControl)dgItem.FindControl("dvGoodRow");
HtmlGenericControl dvBadRow =
(HtmlGenericControl)dgItem.FindControl("dvBadRow");
dvGoodRow.Visible = true;
dvBadRow.Visible = false;
}
Debug sessions show that the Visible attribute I set above does take effect at least in my watch window, but visually on the browser I see no change. I have a grid like the one below:
<asp:datagrid id="dgW" AutoGenerateColumns="False" ShowHeader="False" ShowFooter="False" runat="server" DataKeyField="SID" CellPadding="0" GridLines="None" AllowSorting="True" OnItemDataBound="dgW_ItemDataBound">
<HeaderStyle />
<FooterStyle>
</FooterStyle>
<Columns>
<asp:TemplateColumn HeaderText="SID" SortExpression="SID">
<ItemTemplate>
<asp:Label ID="lblSID" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "SID") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Extension" SortExpression="ExtensionStopDate">
<ItemTemplate>
<asp:Label id="lblExtensionStopDate" Runat="server" text='<%# String.Format("{0:MM/dd/yyyy}", DataBinder.Eval(Container.DataItem, "ExtensionStopDate"))%>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<div id="dvGoodRow" runat="server" hidden>
<div>
<asp:Label runat="server" ID="lblGoodRow">
<i id="icnGoodRow" runat="server"></i>
</asp:Label>
</div>
</div>
<div id="dvBadRow" runat="server" hidden>
<div>
<asp:Label runat="server" ID="lblBadRow">
<i id="icnBadRow" runat="server"></i>
</asp:Label>
</div>
</div>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
Remove that 'hidden' property and use visible
<div id="dvGoodRow" runat="server" visible="false">
<div id="dvBadRow" runat="server" visible="false">
Here's what I ended up doing to fix the code: I switched to showing/hiding ASP.NET Panels instead of DIVs!
<asp:TemplateColumn>
<ItemTemplate>
<asp:Panel runat="server" ID="pnlGoodRow" Visible="False">
<div id="dvGoodRow">
<asp:Label runat="server" ID="lblGoodRow">
<i id="icnGoodRow" runat="server"></i>
</asp:Label>
</div>
</asp:Panel>
<asp:Panel runat="server" ID="pnlBadRow" Visible="False">
<div id="dvBadRow">
<asp:Label runat="server" ID="lblBadRow">
<i id="icnBadRow" runat="server"></i>
</asp:Label>
</div>
</asp:Panel>
</ItemTemplate>
</asp:TemplateColumn>
So in the code, I now hide/show the Panel elements instead of DIVs:
foreach (DataGridItem dgItem in dgW.Items)
{
System.Web.UI.WebControls.Panel pnlGoodRow =
(System.Web.UI.WebControls.Panel)dgItem.FindControl("pnlGoodRow");
System.Web.UI.WebControls.Panel pnlBadRow =
(System.Web.UI.WebControls.Panel)dgItem.FindControl("pnlBadRow");
pnlGoodRow.Visible = true;
pnlBadRow.Visible = false;
}
This works!
I have multiple tabs on my page and currently I am binding all dropdownlists on every tab at page load.
I want to bind the dropdownlists only when the tab is selected. I also want to clear the gridviews when the tab is changed.
This is my HTML code
<li>
<input type="radio" id="tab1d" name="tabs1" runat="server"/>
<label for="tab1d">Search</label>
<div id="tab-content1d" class="tab-content animated fadeIn" style="background-color:white; padding:10px; ">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label4" runat="server" Text="Select Platform"></asp:Label>
<asp:DropDownList ID="DropDownList3" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList3_SelectedIndexChanged" CssClass="inputs" Width="150px"></asp:DropDownList>
<asp:Label ID="Label10" runat="server" Text="Select Family Name"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" CssClass="inputs" Width="150px" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList>
<asp:Label ID="Label11" runat="server" Text="Select price Level"></asp:Label>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="true" CssClass="inputs" Width="150px" ></asp:DropDownList>
<asp:Button ID="Button7" runat="server" Text="Search" CssClass="buttons" OnClick="Button7_Click"/><br /><br />
<div id="gdvLeft">
<asp:GridView ID="gdvFamilyname" runat="server" EnableViewState="True" class="grid" RowStyle-CssClass="rows"></asp:GridView>
</div>
<div id="gdvRight">
<asp:GridView ID="gdvQuantity" runat="server" EnableViewState="True" class="grid" RowStyle-CssClass="rows"></asp:GridView>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</li>
Hi Himani, Try like this -
<input type="radio" value="Click Me" onclick="rdioClick();" />
In Javascript -
function rdioClick() {
var GridView1 = document.getElementById('GridView1');
GridView1.innerHTML = "";
}
Thanks :)
i cannot find my hiddenfield2 in the back end code . So how can i get the value of this hiddenfiled using asp.net(vb)
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div class="list_election">
<form>
<asp:DropDownList ID = "ddlElectionCategorie" runat="server" AutoPostBack="true">
</asp:DropDownList>
</form>
</div>
<div class="row">
<asp:Repeater ID="rpVoteList" runat="server" >
<ItemTemplate>
<div class="col-md-4 ">
<div class="voter">
<h4><%# Eval("List_Nom")%></h4>
<asp:HiddenField ID="hfListId" runat="server" Value='<%# Eval("Id")%>' />
<form>
'this is a nested radiobutton list in a repeater
<asp:HiddenField ID="HiddenField2" runat="server" Value='<%# Eval("Id")%>' />
<asp:RadioButtonList ID="RbCandidat" runat="server"></asp:RadioButtonList>
</form>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
<asp:Button ID="Button1" runat="server" Text="Button" />
</asp:Content>
C#:
foreach (RepeaterItem item in rpVoteList.Items)
{
if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
{
var hf= (HiddenField)item.FindControl("HiddenField2")
}
}
Or
protected void rpVoteList_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
var value = (HiddenField) e.Item.FindControl("HiddenField2")).Value;
}
issue.aspx
<div id="model_input_stock" runat="server" class="form-group well">Dynamically need to insert new textbox and lable with in new div</div>
Issue.aspx.cs
protected void Button_Grid_DT_Assign_Click(object sender, EventArgs e)
{
//use assigned in selecting issued quantity view
foreach(var item in StockCode_List)
{
model_input_stock.InnerHtml.???
}
}
Is their any best alternative way, i'm new in ASP.NET??
You can add an ASP.net panel inside of your div for first and then inside of your foreach loop initialize a new textbox and add it to your panel:
Textbox txt = new Textbox();
txt.id = "txt1";
Txt.Text = "My Text";
Panel.Controls.Add(txt);
Use the following code to do so:
Default.aspx:
<div>
<asp:TextBox ID="txtRows" runat="server"></asp:TextBox>
<asp:Button SkinID="b" ID="btnAddRow" runat="server" Text="Click To Proceed" OnClick="btnAddRow_Click" Width="220px" />
<asp:GridView SkinID="grv" ID="GridViewProducts" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="SL No.">
<ItemTemplate>
<%#Container.DataItemIndex + 1%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Category">
<ItemTemplate>
<asp:DropDownList ID="ddlCategoryID" runat="server" AutoPostBack="True">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Product Name">
<ItemTemplate>
<asp:DropDownList ID="ddlItemID" runat="server" AutoPostBack="True">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quantity">
<ItemTemplate>
<asp:TextBox ID="txtQuantity" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Unit Type">
<ItemTemplate>
<asp:DropDownList ID="ddlUnitTypeID" runat="server" AutoPostBack="True">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<asp:TextBox ID="txtDes" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<div style="padding: 10px 0px;">
<asp:Panel ID="Panel1" runat="server" Visible="false">
<asp:Button ID="btnSave" runat="server" Text="Submit" OnClick="btnSave_Click" />
<asp:Label ID="lblMsg" runat="server"></asp:Label>
</asp:Panel>
</div>
In the code-behind, Default.aspx.cs:
private void AddRowsToGrid()
{
List<int> noofRows = new List<int>();
int noOfInputs = Convert.ToInt32(txtRows.Text);
for (int i = 0; i < noOfInputs; i++)
{
noofRows.Add(i);
}
GridViewProducts.DataSource = noofRows;
GridViewProducts.DataBind();
if (GridViewProducts.Rows.Count > 0)
{
Panel1.Visible = true;
}
else
{
Panel1.Visible = false;
}
}
protected void btnAddRow_Click(object sender, EventArgs e)
{
AddRowsToGrid();
}
Finally you'll have the following output giving input 10:
i have a 1) Text filed
2) Drop down list
3)List Box
Im write code for Drop down list selected value add the the list box and text filed , i can remove the list box value but cant remove the text filed value, please how to write code remove the same adding value for text filed and list box
<div class="col-sm-3">
<asp:TextBox ID="txtQlt" runat="server" CssClass="form-control" Width="348px" OnTextChanged="txtQlt_TextChanged" ReadOnly="true"></asp:TextBox>
</div><div class="col-md-1" style="margin-left:115px;">
<asp:Label ID="Label4" runat="server" ForeColor="Red" Text="*" ></asp:Label>
</div>
</div>
<br />
<div class="row">
<div class="col-sm-2">
<asp:Label ID="Label6" runat="server" Text="Quality reference" Font-Bold="True" Font-Names="arial, helvetica, sans-serif" Font-Size="13px"></asp:Label>
</div>
<div class="col-sm-3">
<asp:DropDownList ID ="cmbQualityRef" runat ="server" CssClass="form-control" Width="250px" >
</asp:DropDownList>
<asp:ListBox ID="lstValue" runat="server" CssClass="content" Rows="5" ValidationGroup="save"
Width="250" ></asp:ListBox>
</div>
<asp:ImageButton ID="btnAdd" runat="server" CssClass="button" Text="Add" ValidationGroup="add"
OnClick="btnAdd_Click" ImageUrl="~/img/Add.png"/>
<asp:ImageButton ID="btnImageRemove" runat="server" OnClick="btnImageRemove_Click"
ImageUrl="~/img/Remove.png" />
<div class="col-md-1" style="margin-left:16px;">
<asp:Label ID="Label7" runat="server" ForeColor="Red" Text="*" ></asp:Label>
</div>
</div>
Code Behind
protected void btnImageRemove_Click(object sender, ImageClickEventArgs e)
{
try
{
if (lstValue.SelectedItem != null)
{
lstValue.Items.Remove(lstValue.SelectedItem);
}
//lstValue.Items.Remove(lstValue.SelectedItem.Text);
}
catch (Exception)
{
}
}
private void AddToList()
{
if (lstValue.Items.Count > 0)
{
txtQlt.Text = txtQlt.Text + "," + cmbQualityRef.SelectedItem.ToString();
}
else
{
txtQlt.Text = cmbQualityRef.SelectedItem.ToString();
}
ListItem itm = new ListItem();
itm.Value = cmbQualityRef.SelectedValue;
itm.Text = cmbQualityRef.SelectedItem.ToString();
lstValue.Items.Add(itm);
lstValue.Items.Remove("");
}
protected void btnAdd_Click(object sender, EventArgs e)
{
AddToList();
lstValue.Items.Remove("");
}
Based on your question as I understand it, when you are removing the selected item, also set the textbox to empty.
if (lstValue.SelectedItem != null)
{
lstValue.Items.Remove(lstValue.SelectedItem);
txtQlt.Text = txtQlt.Text.Replace(lstValue.SelectedItem.ToString(), "");
}
Finally its working
if (lstValue.SelectedItem != null)
{
txtQlt.Text = txtQlt.Text.Replace(lstValue.SelectedItem.ToString(), "").Trim();
lstValue.Items.Remove(lstValue.SelectedItem);
}