Edit the code of a GridView column asp.net - asp.net

I've been looking for a way to control the text that appears in a particular column of a GridView.
For example consider a database with two tables Student and Class.
I want to add a column to the GridView which print out all the students in the Database, the column will show the student's class name, how can do it? (I can normally print the ClassId since its a FK in the student table)
I want to add a column to the GridView which print all the classes, the column will count the number of students in each class, how can I do it?

1- You can do that simply with inner join or a stored procedure to get the class name beside all the data you need in your query.
2- More than one way to do what you want:
For example:
you can add a column to your data table (empty column ), and fill it later through using Sum() aggregate function in a query.
DataTable result_dt = DAL_Helper.Return_DataTable(sqlSelect);//your original query
result_dt.Columns.Add("NumberOfStudent");
result_dt.Columns["NumberOfStudent"].DataType = typeof(string);
result_dt.Columns["NumberOfStudent"].MaxLength = 255;
if (result_dt.Rows.Count > 0)
{
for (int i = 0; i < result_dt.Rows.Count; i++)
{
//Here u can fill your new empty column.
}
}
result_dt.AcceptChanges();
After you return your customized data table(as a data source), you can bind it to the grid view.
Another solution : add an empty column to the grid view and in the RowDataBound event of the grid view you can fill this column through some loop and you can use LINQ to help you in getting the summation.

Related

How to order table view with numbers 1-2-3

I have a table view , and I want to order my rows
for example first row take 1 , the second take 2
I have tried to use
protected static ObservableList<Employee> data = FXCollections.<Employee>observableArrayList();
int i = data.size() + 1;
in my column
But when I delete row ,
and add new row I got bug in order
for example : I have 2 rows , I have delete the first row,
and add new row it should take different order
but I got same number.
I hope you understand my language .
You can call myTableView.sort(); after you added or removed rows. Of course you have to define the sort order first, with a statement like this: myTableView.getSortOrder().add(myColumn);

Delete and update a row in gridview having value of multiple tables

I want to delete and update a row in Gridview but that grid have values of two tables
I'm using following query for selecting-
SELECT JobMaster.Country, JobMaster.City, JobMaster.State, JobMaster.EmploymentType,
JobMaster.JobTitle, JobMaster.SpecializedArea, JobMaster.Specializedskill, JobMaster.ID,
JobMaster.[Post Assign], RAssign.RecruiterID AS Post_Assign FROM JobMaster
LEFT OUTER JOIN RAssign
ON JobMaster.ID = RAssign.JobID
WHERE (RAssign.RecruiterID = #RecruiterID) OR (#RecruiterID IS NULL)
What statement should I use for Update,Insert and for delete?
(Actually I'm new in coding and I just know to delete from single table but in above statement we are selecting to tables data one is "Jobmaster" and second is "RAssign".
Please help me if possible)

How to add values to DataGridColumn dynamically in ASP.net

In the project I am working in there is webpage which retrieve data from the database. So I have used DataGrid show my data.
But sometimes I wanted to add more columns to the DataGrid.That means I want to add some columns with data dynamically.
However I have new columns addition to the DataGrid and here is my code.
DataGridColumn myCol = new BoundColumn();
myCol.HeaderText = "Test";
myCol.Visible = true;
grdHeiskort.Columns.Add(myCol);
In here "grdHeiskort" is DataGrid ID.Now I want to add the data to this column named="test".That data is gain from the database.Suppose I am retrieving dataset from DB and I want to add the data in 1st column in dataset to my "test" column.So how can I do it.
If you use a BoundColumn you can set the name of the DataField to whatever the name of the field you want it to be from your dataset:
BoundColumn myCol = new BoundColumn();
myCol.HeaderText = "Test";
myCol.Visible = true;
myCol.DataField = "NameOfYourDataColumn";
grdHeiskort.Columns.Add(myCol);

How to insert multiple asp.net checkboxes values to MSSQl database as comma seperaed string 1,2,3,4,5 using vb.net?

How to insert and retrive multiple asp.net checkboxes values to MSSQl database as comma seperaed string 1,2,3,4,5 using vb.net ?
and retrieve the inserted checkbox chekched in disabled form ..using vb.net
example of this is :
http://www.redbus.in/Booking/SeatSelection.aspx?rt=4017230&doj=31-Dec-2010&dep=04:55%20PM&showSpInst=false
I want this type of whole layout in vb.net ... means if user registered selected seats then then next the same page load for todays date the selected seats will be disabled ...
pleas provide me the code snippet for that // insert and retrieve funda... in checkbox
Try with such a loop
string str = "";
for (int i = 0; i <= 29; i++)
{
if (CheckBoxList1.Items[i].Selected)
{
string b = CheckBoxList1.Items[i].Value;
str += b + " , ";
}
}
than make an insert statement and you are putting all the checkbox values into a column.
than just call select statement call the column
You are doing a very bad thing storing lists of values in a single MSSQL column. I know it may be convenient now, but it is always eventually bad news. Why not store booked seats in their own table, one seat per row? When you store a list of values in a column, you restrict access to the information stored in that column to only the code that can split the list. It isn't available to database queries or to other code as a list, merely as a string. You will end up replicating the code to split this string to other places that need the list data.

Column Value of multiselect rows in jqgrid

Its like I have multiselect option in Jqgrid in which i want to pass the selected rows value to the server and based on the value i will delete the rows. I dont want to have the ids to do my work. For the Single row i get the cell value and delete using the same. But for multi select its not the case. In getGridParam('selarrrow'); I use this to fetch the selected rows bu the values are not getting populated. Please help me out in doing the same
When i use the following code as i saw in some sample question i can fetch the value for the single row selection but when i select multiple rows then i pass it says like "FALSE" or "UNDEFINED". What can be the issue. var grid = jQuery('#list'); var sel_id = grid.jqGrid('getGridParam', 'selarrrow'); var myCellData = grid.jqGrid('getCell', sel_id, 'CountryId');
I got this done by using the for loop for getting the selected rows id
i did some thing like this and I am able to fetch the value. Thought this might help others too please check it
var myrow;
var id = jQuery("#List").jqGrid('getGridParam','selarrrow');
if(id.length)
{
for (var i=0;i<id.length;i++) // For Multiple Delete of row
{
myrow = jQuery("#List").jqGrid('getCell',id[i],'ticker');
}
}

Resources