|
hi friends i have a problem .... i want to hide all fields from gridview when there is no value in the cell found in a row of gridview .... the gridview is bounded to sqldatabase... through C# code...
plz friends give me some guidence.. thanks in advance
|
|
|
|
|
solo_gaurav wrote: i want to hide all fields from gridview when there is no value in the cell found in a row of gridview
Gaurav,
You want to mean, you want to hide complete row if any of the column field is Blank?
if yes, What is ur sql data source ? Is it DataSet or what ? You have to check in GridView RowBound Event for each column data. Before binding read the source data, if all column available, then bind else move to next records.
This is just an idea, you need to implement it
Let me know if any issue.
|
|
|
|
|
no i dont want to hide whole row.. i just want to hide cell from row...
can i give my code here it is
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.Odbc;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string selectSQL = "SELECT * FROM test ";
OdbcConnection con = new OdbcConnection("Dsn=PostgreSQL35W123;uid=postgres;pwd=abc");
OdbcCommand cmd = new OdbcCommand(selectSQL, con);
con.Open();
cmd.Connection = con;
DropDownList1.DataSource = cmd.ExecuteReader();
DropDownList1.DataTextField = "Journal_Title";
this.DataBind();
con.Close();
DropDownList1.SelectedIndex = -1;
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string selectSQL = "SELECT * FROM test where Journal_Title='" + DropDownList1.SelectedItem.Text + "'";
OdbcConnection con = new OdbcConnection("Dsn=PostgreSQL35W123;uid=postgres;pwd=abc");
OdbcCommand cmd = new OdbcCommand(selectSQL, con);
con.Open();
cmd.Connection = con;
cmd.ExecuteNonQuery();
OdbcDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
GridView1.DataSource = dr;
GridView1.DataBind();
Label1.Text = "found";
}
else
{
Label1.Text = "not found";
}
}
}
now i want that when a dropdownlist item is selected then it show a griview with only those cells which has data in them... and the cell with no data(null) , i want them to be hidden abhijit plz help if you get it
|
|
|
|
|
solo_gaurav wrote: if (dr.HasRows)
{
GridView1.DataSource = dr;
GridView1.DataBind();
Label1.Text = "found";
}
So rather than assigning Gridview Source over here, you just create a Temp Arraylist/ Dataset from the DataReader(Dr) with those rows you wants. Then assing the Team DataSource to GridView.
Hope you have understand what I am saying
|
|
|
|
|
you are saying right but.. i cant change code but only add new block of code to it..
means i want some lines of code that could help me in ommiting those cells which have null value
|
|
|
|
|
Hi all,
Following is my code for setting the data source for a cystal report which i m using in my project.
protected void DDL_Departments_SelectedIndexChanged(object sender, EventArgs e)
{
int deptid=int.Parse(DDL_Departments.SelectedValue);
EmployeesTableAdapters.Get_Employee_By_Department _emp_adapter=new EmployeesTableAdapters.Get_Employee_By_Department();
Employees.EmployeesDataTable _emp;
_emp=_emp_adapter.Get_Employees_By_Dept(deptid);
_rdc.SetDataSource(_emp);
CR_Emp_Viewer.ReportSource=_rdc;
CR_Emp_Viewer.DataBind();
}
but its giving me a compile time error stating
CS0121: The call is ambiguous between the following methods or properties: 'CrystalDecisions.CrystalReports.Engine.ReportDocument.SetDataSource(System.Collections.IEnumerable)' and
'CrystalDecisions.CrystalReports.Engine.ReportDocument.SetDataSource(System.Data.DataTable)'
What do i need to do to solve this issue????
Also its surprising that a similar code i wrote in VB runs successfully.:confused::confused::confused:
I am using VS 2005, 2.0 framework.
When you fail to plan, you are planning to fail.
|
|
|
|
|
I believe reportdatasource(_rdc) expects IEnumerable Collection, while you are passing DataTable, which is not an IEnumerable Collection. So it throws the error.
If you are in 3.5, you can call DataTable.asEnumerable()
here you need to pass _emp.Rows collection which is IEnumerable collection.
Try out this. I have never found this before, Hope it works.
|
|
|
|
|
Abhishek Sur wrote: I believe reportdatasource(_rdc) expects IEnumerable Collection, while you are passing DataTable, which is not an IEnumerable Collection. So it throws the error.
But SetDataSource provides four overloads from which one does accepts a DataTable.
I am pretty confused as to why it recognises the data table as an IEnumerable.
When you fail to plan, you are planning to fail.
|
|
|
|
|
this is weird.
Try to do this, and see if it works or not:
Employees.EmployeesDataTable _emp;
_emp=_emp_adapter.Get_Employees_By_Dept(deptid);
DataTable dt = _emp.Table;
_rdc.SetDataSource(dt);
Pass the Table to the SetDataSource rather than your class.
|
|
|
|
|
|
Please don't Cross Post. I Guess its by mistake
|
|
|
|
|
Hello, Ive got a problem with Gridview!
I want access to column's data that is checked.
and I dont know why this code doesnt work.
The value of "chbxRmove.Checked" always is False even when the column is checked !!!
plz help me.
foreach (GridViewRowgridRowinthis.GridView1.Rows)<br />
{<br />
CheckBoxchbxRmove = (CheckBox)gridRow.FindControl("chkSelect");<br />
if (chbxRmove.Checked)<br />
{<br />
}<br />
}
|
|
|
|
|
Probably checkbox is losing state on load event of Page,check it carefully.
By the way,if you had problems with internet connection then delete one post of your same question.
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.aktualiteti.com
|
|
|
|
|
I'm very grateful that you attended to my question
but Abhijit's answer was more comprehensive than your answer.
|
|
|
|
|
I guess you are binding the Gridview data on Page_Load and you are not checking the Postback properties, which reset the Grid Check box field.
Try this
if(!Page.IsPostBack)
{
}
Hope this will help you.
|
|
|
|
|
Thank u very very much
|
|
|
|
|
And what is difference between my answer and Abhijit's answer?
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.aktualiteti.com
|
|
|
|
|
also I've anather question.
How do I get selected row's data (Like ID)?
modified on Monday, July 27, 2009 4:46 PM
|
|
|
|
|
comp_j wrote: How do am I get selected row's data (Like ID)?
There is a class GridViewRow, on SelectedIndexChnaged event of Grid, Read the current Selected Row in GridViewRow, then you can read each and every column from it. Even you can read directly the data.
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
int ID= Int32.Parse(GridView1.Rows[GridView1.SelectedIndex].Cells[0].Text);
}
Note : I assume, Cell[0] of Grid contain your ID
Hope this will help you
|
|
|
|
|
foreach (GridViewRow gv in gvShowUser.Rows)
{
CheckBox chk = (CheckBox)gv.FindControl("chkEditUser");
if (chk.Checked)
{
//uid = ((Label)gv.FindControl("lblEditUserId")).Text.ToString();
//userid = Convert.ToInt32(uid);
//cnt++;
}
}
|
|
|
|
|
Hi All,
I have a table used to display few items, that table's width is reduced and is using horizontal scroll bar to view all the columns. When that is displayed in IE it is howing the headers properly means the header width is equal to the column width of the items.
when it is viewed in Mozilla or Safari browsers the header widths are reduced but, items column widths are remaining same, which is looking very odd. And when it is viewed completely without horizontal bar in all the browsers the headers widths are good again.
Can anybody please advice me its header widths remain same in all the browsers along with its horizontal bar.
Thanks in advance,
Mohammad Abdul Aleem.
Thanks & Regards,
Md. Abdul Aleem
NIIT technologies
|
|
|
|
|
|
The source is here for the header but
<th class="RowHeader2Cell1" align="left" style="white-space:nowrap;">Asset Name</th>
Thanks,
Mohd Abdul Aleem.
Thanks & Regards,
Md. Abdul Aleem
NIIT technologies
|
|
|
|
|
The problem is IE6 renders scrollbar outside the working area where others renders it inside.
|
|
|
|
|
hello ,
i just want pass the LINQ query in string format from java script to the code behind and then here execute the this string formatted LINQ query.....
public static IList getUserListForGrid(string sQuery)
{
DALDataContext Context = new DALDataContext();
-->i want your help here
->-> Execute sQuery ?????? :omg:
}
|
|
|
|