In my single page two buttons are there. one button is using 3 tier structure to insert data in to database and it is perfectly running.
Button coding
<asp:Button ID="InsertButton1" CssClass="BUTT" runat="server" OnClick="Insert" CommandName="Insert" Text="SUBMIT" />
second button code
<asp:FormView ID="FormView1" runat="server" DefaultMode="Insert" DataKeyNames="id" DataSourceID="SqlDataSource1" EnableModelValidation="True">
<InsertItemTemplate>
<table>
<tr>
<td>
Office Address
</td>
<td>
<asp:TextBox ID="office_addressTextBox" runat="server" Text='<%# Bind("office_address") %>' />
</td>
</tr>
<tr>
<td>
Date Of Birth
</td>
<td>
<asp:TextBox ID="dobTextBox" runat="server" Text='<%# Bind("dob") %>' />
</td>
</tr>
<tr>
<td>
Sex
</td>
<td>
<asp:TextBox ID="SexTextBox" runat="server" Text='<%# Bind("Sex") %>' />
<asp:Button ID="InsertButton" runat="server" CausesValidation="true" CommandName="Insert" Text="insert" />
</td>
</tr>
</table>
</InsertItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues"
ConnectionString="Data Source=WIN-MIUHU8FBDQI\PANKIL;Initial Catalog=test;Integrated Security=True"
InsertCommand="INSERT INTO [research] ([office_address], [dob], [Sex]) VALUES
(#office_address, #dob, #Sex)" OldValuesParameterFormatString="original_{0}"
ProviderName="System.Data.SqlClient" >
<InsertParameters>
<asp:Parameter Name="office_address" Type="String" />
<asp:Parameter DbType="Date" Name="dob" />
<asp:Parameter Name="Sex" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
i want that when any one click on one button , second button also perform a insert task.
I'm unsure if there is a way to trigger that in asp. But i think JQuery can do that for you.
However a neater way to do it as stated by #Luaan is calling the click event and handle it in the cs code. This way it promotes reuse of codes and no update/change of codes problems.
asp page:
<asp:Button ID="FirstButton" CssClass="BUTT" runat="server" OnClick="onclick="button1_Click" Text="SUBMIT" />
<asp:Button ID="SecondButton" CssClass="BUTT" runat="server" OnClick="onclick="button2_Click" Text="SUBMIT" />
Here in the cs code you handle the event.
I think you want this :
private void button1_Click(object sender, EventArgs e)
{
button2_Click(sender, e);
}
However a neater way would be this:
private void button1_Click(object sender, EventArgs e)
{
InsertIntoDatabase();
}
private void button2_Click(object sender, EventArgs e)
{
InsertIntoDatabase();
}
private void InsertIntoDatabase()
{
// Your Insert into Database codes here
}
So any adjustment to your insert query can be in the method InsertIntoDatabase().
Related
I'm trying to use the DataTextField property of a dropdown list to finish the link to the page it is supposed to navigate to. Here's the code:
page1.aspx
<table>
<tr>
<td>Search by last name: <asp:TextBox ID="searchTB" runat="server"/><br />
Search by first name: <asp:TextBox ID="FNameTB" runat="server"/><br />
</td>
<td style="padding-left: 10px;">
Search by Organization: <asp:DropDownList ID="OrgDDL" runat="server"
DataSourceID="AccessDataSource2" DataTextField="SectionName"
DataValueField="ID">
</asp:DropDownList>
<asp:AccessDataSource ID="AccessDataSource2" runat="server"
DataFile="~/App_Data/webvideos.mdb" SelectCommand="SELECT * FROM [ORG_SECTIONS]">
</asp:AccessDataSource>
</td>
</tr>
<tr>
<td style="text-align: center;"><asp:Button ID="Button1" runat="server" Text="Search" OnClick="Search" /></td>
<td style="padding-left: 10px; text-align: center;"><asp:Button ID="SearchbyOrgBtn" runat="server" Text="Search" OnClick="SearchByOrg" /></td>
</tr>
</table>
Code behind:
protected void Search(object sender, EventArgs e)
{
//TextBox LastName = (TextBox)this.FindControl("searchTB");
Response.Redirect("OrgsByName.aspx?LASTNAME=" + searchTB.Text);
}
protected void SearchByOrg(object sender, EventArgs e)
{
//TextBox LastName = (TextBox)this.FindControl("searchTB");
Response.Redirect("NamesByOrg.aspx?SectionName=" + OrgDDL.DataTextField);
}
NamesByOrg.aspx:
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/webvideos.mdb"
SelectCommand="SELECT ORGANIZATIONS.ORG_NAME, ORG_SECTIONS.SectionName, ATTORNEYS.NAME, ATTORNEYS.LASTNAME, ATTORNEYS.EMAIL, ATTORNEYS.TEL
FROM (ORGANIZATIONS INNER JOIN (Org_Sec_Atty INNER JOIN ATTORNEYS ON Org_Sec_Atty.Atty_ID = ATTORNEYS.ATTY_ID) ON ORGANIZATIONS.ID = Org_Sec_Atty.OrgID) INNER JOIN ORG_SECTIONS ON Org_Sec_Atty.SecID = ORG_SECTIONS.ID
WHERE ORG_SECTIONS.SectionName LIKE #SectionName;">
<SelectParameters>
<asp:QueryStringParameter Name="SectionName" QueryStringField="SectionName" />
</SelectParameters>
</asp:AccessDataSource>
It doesn't matter what value I select in the DDL, it always tries to navigate to "NamesByOrg.aspx?SectionName=SectionName". When I had it as a textbox, it worked fine, but I'd like to keep it as a DDL for obvious reasons, lol.
The value of DataTextField is defined in the .aspx that you've provided, which happens to be "SectionName".
What you're looking for is something like SelectedValue or SelectedItem which will return whatever you selected in the drop down.
I have a datalist control which is connected to a SQLDataSource when i test the data source query with the query builder it returns the data set however when i then run the website in any browser the query does not return a data set.
It seems like the website is not recompiling properly however i am not getting any build errors.
Does anyone have any idea for a possible solution.
Thanks in advance
my sqldatasource code is-
<asp:SqlDataSource ID="SqlDataSourceSearch" runat="server" ConnectionString="<%$ ConnectionStrings:BazaarCeramicsConnectionString %>"
SelectCommand="SELECT Categories.Name, Products.ProductID, Products.Name AS Expr1 FROM Products INNER JOIN Categories ON Products.CategoryID = Categories.CategoryID WHERE (Products.Name LIKE '%' + #SearchQuery + '%')">
<SelectParameters>
<asp:QueryStringParameter Name="SearchQuery" QueryStringField="search"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
my datalist code is-
<asp:DataList ID="DataList1" runat="server" DataKeyField="ProductID" DataSourceID="SqlDataSourceSearch">
<ItemTemplate>
Name:
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
<br />
ProductID:
<asp:Label ID="ProductIDLabel" runat="server" Text='<%# Eval("ProductID") %>' />
<br />
Expr1:
<asp:Label ID="Expr1Label" runat="server" Text='<%# Eval("Expr1") %>' />
<br />
Here is my input-
<div class="searchBox">
<asp:TextBox ID="SearchTextBox" runat="server"></asp:TextBox>
<asp:Button ID="SearchButton" runat="server" onclick="Button1_Click" Text="Search" />
<img id="cartIcon" src="Images/shoppingCartIcon.png" />
</div>
Here is the code behind
protected void Button1_Click(object sender, EventArgs e)
{
string SearchTerm = SearchTextBox.Text;
Response.Redirect("SearchResults.aspx?SearchQuery=" + Server.UrlEncode(SearchTerm));
}
here is my connection string-
<add name="BazaarCeramicsConnectionString" connectionString="Data Source=CATHERINE\SQLEXPRESS;Initial Catalog=BazaarCeramics;User ID=****;Password=******"
providerName="System.Data.SqlClient" />
(Products.Name LIKE '%' + #SearchQuery + '%')
Currently I have a dropdownlist with it's own sqldatasource that's populating the dropdownlist.
The ddl is inside a listviews, which also has it's on sqldatasource, insert item template.
However when we click insert the value passed to the dbase is a null.
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert"
Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Clear" />
</td>
<td>
</td>
<td>
<asp:TextBox ID="td_t_idTextBox" runat="server" Text='<%# Bind("td_t_id") %>' Enabled="false" />
</td>
<td>
<asp:DropDownList ID="DropDownList2iit" runat="server" DataSourceID="SqlDataSource30"
DataTextField="document_name" DataValueField="document_id"
SelectedIndex='<%# Bind("td_docid") %>'>
</asp:DropDownList>
</td>
</tr>
</InsertItemTemplate>
I have tried to use both document_id and td_docid in my sqldatasource insertparameters.
<InsertParameters>
<asp:Parameter Name="td_t_id" Type="Int32" />
<asp:Parameter Name="td_docid" Type="Int32" />
<asp:Parameter Name="document_id" Type="Int32" />
</InsertParameters>
however neither value when used will give me a actual value other than null. Is this a common occurance?
update: I ended up using the oniteminserting to do a little code behind magic
protected void ListView2_OnItemInserting(object sender, EventArgs e)
{
string sv = ((DropDownList)ListView2.InsertItem.FindControl("DropDownList2iit")).SelectedValue;
SqlDataSource31.InsertParameters.Add("document_id", sv);
}
and it works like it should.
You can try like bellow . ( i am 100% sure but hope fully it's worked)
protected void ListView2_OnItemInserting(object sender, EventArgs e)
{
string sv = ((DropDownList)e.Item.FindControl("DropDownList2iit")).SelectedValue;
SqlDataSource31.InsertParameters.Add("document_id", sv);
}
This question is very old but might help someone.
You are binding your drop down's value to selectedindex property. It should be bound to SelectedValue instead. No need of writing code for this..
Replace :
SelectedIndex='<%# Bind("td_docid") %>'>
with
SelectedValue= '<%# Bind("td_docid") %>'
I want to show some data in tool tip on mouse hover. I am using datalist in asp.net. How can I show dynamic data in tool tip.The data will be based on database tables. This is the code for my datalist and I want tool tip to be shown on item template. The tooltip data will contain 3 items viz available quantity,on hand quantity and on order quantity.
EDIT: I tried ways provided in answer of this question but they are not working.
Is there any way that I can do the same using JQuery and web service? If yes then please guide me the proper way...
<asp:DataList ID="dlvProductSpecification" runat="server" RepeatColumns="10" HeaderStyle-Font-Size="16px"
Font-Size="Smaller" OnItemCommand="dlvProductSpecification_ItemCommand" OnItemCreated="dlvProductSpecification_ItemCreated"
OnItemDataBound="dlvProductSpecification_ItemDataBound">
<ItemStyle Font-Size="Smaller" />
<HeaderStyle HorizontalAlign="Center"> </HeaderStyle>
<HeaderTemplate>
<table class="header_dl">
<tr>
<td>
SPECIFICATION HEADER
</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<%--<table style="text-align: center;">--%>
<table class="style_dl" onmouseover="showtooltip()" onmouseout="hidetooltip()">
<tr>
<td class="style_dl_td">
<asp:Label ID="lblReferenceNo" CssClass="labeltitle_dl" runat="server"><%# Eval("ReferenceNo")%></asp:Label>
<br />
<asp:Label ID="Label1" runat="server"><%# Eval("Specification")%></asp:Label>
<br />
<br />
<asp:HiddenField ID="hdnSpecificationID" runat="server" Value='<%# Eval("ProductSpecificationID")%>' />
<asp:HiddenField ID="hdnSpecification" runat="server" Value='<%# Eval("Specification")%>' />
<asp:HiddenField ID="hdnReferenceNo" runat="server" Value='<%# Eval("ReferenceNo")%>' />
<asp:HiddenField ID="hdnGTIN" runat="server" Value='<%# Eval("GTIN")%>' />
<asp:HiddenField ID="hdnAvailableQty" runat="server" Value='<%# Eval("AvailableQty")%>' />
<asp:Button ID="btnAddQty" runat="server" CommandName="GetData" Text="Add" /><br />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
You can do it on ItemDataBound event. Try this:
protected void dlvProductSpecification_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||e.Item.ItemType== ListItemType.AlternatingItem)
{
e.Item.ToolTip = "Tool Tip";
}
}
Inside your Item templates' Label put a toolTip property and bind it like this:
<asp:Label ID="Label1" runat="server" ToolTip='<%# Eval("Specification") %>'><%# Eval("Specification")%></asp:Label>
hope it works.
I have a modalpopup which is showed automaticaly on startup of page. I'm doing this on Page_Load event.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
InitiallizeAll();
}
}
private void InitiallizeAll()
{
ModalPopupExtender1.Show();
}
In aspx side I have a dropdownlist on a modalpopup but the index is always posting zero to the javascript code.
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
TargetControlID="lnkPopup"
PopupControlID="panEdit"
BackgroundCssClass="modalBackground"
OkControlID="btnGonder"
OnOkScript="onOk()">
</asp:ModalPopupExtender>
<asp:Panel ID="panEdit" runat="server" Height="180px" Width="400px" CssClass="modalPopup">
<table width="100%">
<tr>
<td class="labelCell">
<asp:Label ID="lblBolge" Text="Bölge" runat="server" />
</td>
<td>
<asp:DropDownList ID="ddlIl" runat="server"
AutoPostBack="False"
DataTextField="Isim"
DataValueField="Id"
DataSourceID="ObjectDataSource1"
Width="176px">
</asp:DropDownList>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetAllIl"
TypeName="ERK.Lasos.Business.CustomEntities.Il">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="0"
Name="ilId"
QueryStringField="bolge"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
</td>
</tr>
</table>
<br />
<asp:Button ID="btnGonder" runat="server" Text="Devam Et" />
</asp:Panel>
<a id="lnkPopup" runat="server">Show Popup</a>
And this is my javascript code
<script type="text/javascript">
function onOk() {
var e = document.getElementById("ddlIl");
var selectedIlId = e.options[e.selectedIndex].value;
window.location = "/Pages/AnaSayfa/LasosAnaSayfa.aspx?bolge=" + selectedIlId;
}
</script>
But I'm always getting selectedIlId is "0". Value is not changing whatever I select from dropdownlist
First, you should check if you got the good selected index. :
Replace temporally var selectedIlId = e.options[e.selectedIndex].value; by var selectedIlId = e.selectedIndex;
If it's OK, you should check you data source by making sure the Id field is correct, the easiest way to to this is to set DataTextField="Id" to your DropdownList and check the values that appears in it.