|
|
Thank you very much Richard, as always.
You can see that I am actually using parametized query but commented it out just to get the code to work first before using it again.
|
|
|
|
|
You'll need to debug your code, apart from the typo (uerystring("dept")) we don't know what is wrong as we can't run your code in context, we don't know your inputs and we don't know your data. If it "doesn't work" then I suggest you examine the command you are building as querystring("ID") or querystring("dept") might not be what you think they are. If the manager ID is numeric then the issue might be that you're wrapping it in quotes which is only for text
"SELECT e.empID, e.empname, e.department, a.managerID, a.status FROM Emp e INNER JOIN Angulers a ON a.empID = e.empID WHERE a.status = 'Done' and e.ManagerID = "&querystring("ID") & " and e.department = '"&querystring("dept") & "' ")
|
|
|
|
|
I am really sorry guys.
I was showing wrong code.
The correction made by Richard is great and will be used on employeeDetails.aspx page.
However, where my issue lies on the current page.
We would like to show all records related to a department to be displayed when the manager of that department logs on to that page.
As a result, I am trying to use the managerId and department to filter the records.
I am trying to hide the managerId and department Id on the markup but use them to filter the records.
Currently, I am using just the department. If it works, I will add the manager but the department is not working.
Here is the department that I added to the gridview:
<asp:BoundField DataField="department">
<ItemStyle CssClass="dhide"/>
<asp:BoundField DataField="department">
<ItemStyle CssClass="dhide"/>
and I want to pass the value to the SELECT statement on codebehind.
Any ideas how to do this?
I will show the code again for clarity with some slight modifications:
<head>
<style type="text/css">
.dhide
{
display:none;
}
</style>
</head>
<div align="center">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" AllowPaging="true"
OnPageIndexChanging="OnPageIndexChanging" PageSize="10">
<Columns>
<asp:BoundField DataField="department">
<ItemStyle CssClass="dhide"/>
<asp:HyperLinkField DataNavigateUrlFields="ManagerID,department"
DataNavigateUrlFormatString="employeeDetails.aspx?ID={0}&Dept={1}" Text="Add Comments" />
<asp:BoundField ItemStyle-Width="200px" DataField="empname" HeaderText="Employee Name" />
<asp:BoundField ItemStyle-Width="250px" DataField="department" HeaderText="Department" />
</Columns>
</asp:GridView>
</div>
'//Code behind:
<pre> Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Me.BindGrid()
End If
End Sub
Private Sub BindGrid()
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand("SELECT e.empID, e.empname, e.department, a.managerID, a.status FROM Emp e INNER JOIN Angulers a ON a.empID = e.empID WHERE a.status = 'Done' and e.ManagerID = '"&querystring("ID") & "' and e.department = '"&uerystring("dept") & "' ")
'We use parametized query to prevent sql injection attack
' Dim p1 As New SqlParameter("@dept", Session("dept"))
'cmd.Parameters.Add(p1)
Using sda As New SqlDataAdapter()
cmd.Connection = con
sda.SelectCommand = cmd
Using dt As New DataTable()
sda.Fill(dt)
GridView1.DataSource = dt
GridView1.DataBind()
End Using
End Using
End Using
End Using
End Sub
|
|
|
|
|
Any data you want to store and get back on postback but you don't need to be a visible or editable field can be stored in the ViewState.
ViewState["DepID"] = id;
to read it after postback
int id = (int)ViewState["DepID"];
|
|
|
|
|
My question though is how do I grab the value of the following and:
<style type="text/css">
.dhide
{
display:none;
}
</style>
<asp:BoundField DataField="department">
<ItemStyle CssClass="dhide"/>
</asp:BoundField>
and pass it to the SELECT query on the BindGrid sub in codebehind and use it as filter like WHERE e.department = the value of dhide
How do I do that?
|
|
|
|
|
I never use binding like that I'm afraid, however rather than using a datagrid to "store" data (something you see a lot of) you should remember that it is simply there to *display* data. The grid is simply being bound to a datasource and if you want to read values then you should read them direct from the datasource you are binding the grid too rather than the grid itself.
It might be advisable to leave datagrids etc behind and use more basic mechanism like repeaters etc, and using the code-behind to bind your data rather than using auto-bound template fields. You end up with greater control over things.
|
|
|
|
|
Hi!
I was trying to open a Javascript pop up on click of button. Though I am able to open the pop up, but my problem is it does not file the onlclick event of the button.
---code for opening the pop up-----
<a href="#" title="Edit" style=" background-color:#FFF;" data-toggle="modal" data-target="#myModal1" style="background-color:#FFF;">
<asp:ImageButton id="imgedit" runat="server" ImageUrl="boot/img/pen2.png" CommandName="BtnEdit" style="width:20px; height:20px;"/></a>
------------------------------
My above code opens up the popup but the code written behind onclick event is not firing.
Please suggest how I can make my click event work and open the javascript popup
Thanks & Regards
|
|
|
|
|
You've got no onclick event on the imagebutton itself. Easiest way is to double click it in your VS designer as this'll generate the blank method for you and put you into the .cs/.vb/.whatever codebehind you're using.
Downside: It'll postback your page which should stop your popup. What are you trying to achieve exactly?
|
|
|
|
|
You can't really open a pop-up and also do the server-side click event. The javascript click will add a div to the current document, the button click would fire which will trigger a request to your server code, which will run the server-side click event which will result in the document in the browser being replaced with the new document from the server so the div that your js added is now gone. You'll probably need to add code to the server-side click event of your button to create the pop-up when the document has finished rendering.
An Interactive jQuery Modal Popup Control for .NET[^]
|
|
|
|
|
Hello All,
I am new to the web technology, I would like to know, how can i call ASP.net Web Service in a HTML page using java script.
Any sample is appreciated.
Thanks in advance.
|
|
|
|
|
Go to www.asp.net[^] where you will find a wealth of information to get you started.
|
|
|
|
|
If you have some knowledge of JQuery, you can use the jQuery.ajax() function.
|
|
|
|
|
Hi All,
Thanks for your replies.
Struggled bit to use web service with JavaScript, and we are proceeded with WCF service, and succeeded in consuming the developed WCF service.
Consuming the web service in HTML page with JavaScript is still looking for the solutions.
Thank you.
|
|
|
|
|
With what are you struggling?
|
|
|
|
|
Hi Everyone
I am hoping someone can help me out. I have my pages setup as https://domain.com/about.aspx. My site works normal and everything is cool but I was not being indexed by Google. I checked a site and it confirmed I have a url error so when someone types in https://domain.com/about.aspx/
my site comes up with all the images missing but all the text there.
Does anyone know why?? I am assuming the correct response should be a 404 or the aspx work.
Hoping someone can help!
Thanks T
|
|
|
|
|
The server may be returning 404's for the images, but that is not how the browser will render it. It will simply show those placeholder "X" images.
You need to look at the img tags in your about.aspx document and make sure they have the correct URL's.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Looks like my developer does not have the backslash on the anything so for example /images/image1.png rather images/image1.png. This is for everything not just the images but href, etc..
So to be sure if you go to domain.com/about.aspx/ it should show the .aspx page again and not give a 404??
Thanks T
|
|
|
|
|
Well, if the server is able to locate the "about" document, then it won't give a 404 for it. The server will send the "about" document down to the browser.
However, if the src's for the images don't point to valid image files, then the server won't be able to locate them.
So apparently, the browser is receiving the "about" document but not the images.
The difficult we do right away...
...the impossible takes slightly longer.
modified 20-Sep-15 22:49pm.
|
|
|
|
|
Are you still running .NET 3.5? It looks like this bug was fixed in 4.0:
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
$("#select2_sample5").select2({
tags: ["one","two"]
});
This is the code in .js file, now the problem is i want to add tags dynamically in mvc 5, can any one help me ?
I am trying like below, but nothing happens !!
$("#select2_sample5").select2({
query: function () {
$.getJSON('/Web/StateList/', function (data) {
var items = "";
$.each(data, function (i, country) {
items += country.Name + ",";
});
tags: ["one", "two"]
});
}
});
modified 20-Sep-15 19:30pm.
|
|
|
|
|
You have a syntax error in your javascript - you can't declare the tags property within the query function.
You're also using a deprecated feature:
Deprecated in Select2 4.0. This has been replaced by another option and is only available in the full builds of Select2.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
How to Fetch data into sql-server database using javaScript Code? Without use any .net classs(sqlconnecton,DataAdpter,SqlCommand)
|
|
|
|
|
It is not possible with a very good reason. JavaScript is client-side, meaning that everyone can have a peek at your JavaScript source and will cause a huge security risk, it will open doors to SQL Injection. Only way of accessing Database with JavaScript is by creating a web service were you have more control over the sql connection.
|
|
|
|
|
it's not Possible. (Javascript in client side language).
and what you exactly want to do?
|
|
|
|