I have a dropdownlist of ID=ddlDept which shows the department from a column named DId and table named Department. Under that selected department there are students with StudentID from the column named StudentID and table named registration which i have done by inner join operation. Now I want to auto populate a textbox in a aspx webform with the incremented StudentID by selecting from ddlDept.
Before selecting ddlDept Suppose i had ddlDept of 02 and the last studentID in that "02" department is 0705044.
Now if I select "02" from ddlDept then the textbox for StudentID must populate with the value of 0705045
Also if the Student ID is 0405089 then by selecting the ddlDept it must populate with 0405089.
That means increment will be of the last 2 digits only.
I am very stuck.Suggest with sample code.Thnx in advance
Related
I have two tables
Employee
Finance
Employee contains 3 columns
id
Name
BaseSalary
Finance table contains 2 columns
id
BonusPercentage
I want to add TotalBonus column in Employee table. For calculation I am using BaseSalary from Employee table and BonusPercentage from Finance table.
TotalBonus = BaseSalary + (BaseSalary * BonusPercentage)
I can use this with stored procedure but i don't want. However, I created scalar function (calculateBonus) which returns TotalBonus but the problem is that i can't add column in table as i have dependency of BonusPercentage of Finance table.
In general i want employee table to have following:
id
Name
BaseSalary
TotalBonus
I know there are many ways but want in Employee table as I am using this table on C#.
Thanks
Assuming that there can be a maximum of one row in finance for each employee, you want a (left) join:
SELECT e.id,
e.name,
e.basesalary,
coalesce(f.bonuspercentage, 0) * e.basesalary totalbonus
FROM employee e
LEFT JOIN finance f
ON f.id = e.id;
I have a table with 3 columns
EmployeeId EmployeeName ReportingTo
1 A
2 B 1
3 C 1
4 D 1
5 E 2
6 F 3
7 I 3
8 J 4
9 K 8
Employee Ids are unique. ReportingTo is id of person to whom employee is reporting. ReportingTo is null means A is Boss.
In Asp.net, I want to create a page with one dropdownlist by default. In that dropdownlist EmployeeId whose reportingto is null will be loaded. when I select that dropdown with EmployeeId 1 then next dropdownlist will get created & fill with employees who are reporting to EmployeeId 1.
I have created this whole page, but for that i am generating dropdownlist manually in aspx page.
Anyone can guide me how to create this scenario with dynamic dropdownlist, so I can generate any number of dropdowns & fill it dynamically.
You can add a placeholder control on your web page and then create the new dropdown and add it to the placeholder like so:
private void AddDropDown(){
var dl = new DropDownList();
dl.ID="empDDL";
dl.DataSource = list;
dl.DataBind();
myPlaceholer.Controls.Add(dl);
}
Hope this helps.
You use ASP.Net cascade dropdownlist. This example
http://www.aspsnippets.com/Articles/Creating-Cascading-DropDownLists-in-ASP.Net.aspx
I have 2 table :
table1: name, family, cityID
table2: cityID, cityName
I have a gridview that it's datasource is:
select * from table1, table2 where table1.cityID = table2.cityID
I disable autoCreatColumns
I add 3 columns to my datagrid.
in first column I fix the data property name to name
in second column I fix the data property name to family
but in third colum when I fix the data propery name to table2.cityName It dosent work...
I want to show the city name in third column.
Its an example but in fact, I have cityName in anouther table that I used, and if I use just cityName, makes error
can any body help me?
Thanks...
try to change
select * from table1, table2 where table1.cityID = table2.cityID
To
select table1.name as Name,table1.family as Family,table2.cityName as City from table1, table2 where table1.cityID = table2.cityID
SELECT name,family,cityName from table1 INNER JOIN table2 ON table1.cityID = table2.cityID
As you are doing inner joins with city ids on both tables..U will get matched Table IDs with name,citynames
You don't need to write table2.cityName, just write cityName and it should work.
I have the following database structure:
T_CUSTOMER: ID (PK), F_NAME varchar
T_ORDERS: ID (PK), ID_CUSTOMER (FK), F_ORDER_DATE datetime
The DataGridView displays data from table T_ORDERS, and I would like to be able to filter and sort results by customer name ("F_NAME LIKE '% s%', 'ORDER BY F_NAME').
All I can do is filter and sort the ID_CUSTOMER column that contains values numbers. How can most easily make this type of filter for a column containing a foreign key, and being a DataGridViewComboBoxColumn.
I have a gridview, when inserting data into the table dept(100, 1, 'IT') and when fetch the data from two tables emp and dept the records look like below grid:
EMpNo DeptNo DeptName
Harshal 1 IT
My problem is that, when I click on a grid view all records shows in respected text boxes
but issue is, I got all data except empno. Here I get as Name of employee instead of name I want to Empno.
you can try like this
select empno,deptno,deptname from emp inner join dept on emp.dept.id=dept.id