Im selecting all records from no of columns from 5 tables by joining.
aftre bind it to gridview want to search records on demand on columns without go to server?
so how to to do that?by xml or datatable or dataset then how?
Know the answer? Post it. Somebody with the same question will find it here.
Khargesh RajputRank #616 · 3.9K reputationPosted Mar 26, 2015, 2:13 AM EDT
as
public DataSet Ds
{
get
{
object temp = ViewState["Ds"];
return temp == null ? null : temp as DataSet;
}
set
{
ViewState["Ds"] = value;
}
}
step 2
bind gridview on postback check
Ds = objdal.FillDataSet(CommandType.StoredProcedure, "sp_getTopic");
if (Ds.Tables[0].Rows.Count > 0)
{
grdSearch.DataSource = Ds.Tables[0];
grdSearch.DataBind();
}
}
step 3
on search buttonclick
string strFieldNm;
strFieldNm = ddl_Search.Text.Trim();
if (strFieldNm == "Category")
{
strFieldNm = "category_name";
}
if (strFieldNm == "Class")
{
strFieldNm = "class_name";
}
if (txt_Search.Text.Trim().Length > 0)
{
DataTable dt = new DataTable();
dt = Ds.Tables[0];
dt.DefaultView.RowFilter = "Convert([" + strFieldNm + "],'System.String') Like '" + txt_Search.Text.Trim().Replace("'", "''") + "%' ";
grdSearch.DataSource = dt;
grdSearch.DataBind();
}
here i have search by dropdown(by columnname of database you want to search) and textbox for keyword you want to search
i have bind dropdown statically as
Category,Class and category_name,class_name are columnname from dataset
I hope It may help you
Azaad Abbas127 reputationPosted Mar 30, 2015, 10:13 PM EDT
bind gridview on postback check /*MEAN BEFORE !iSpOSTbACK CHECK? OR IN SIDE?*/
Ds = objdal.FillDataSet(CommandType.StoredProcedure, "sp_getTopic"); /*WHAT IS objdal?*/
Khargesh RajputRank #616 · 3.9K reputationPosted Mar 30, 2015, 10:15 PM EDT
if (!Page.IsPostBack)
{
//code to bind
}
Azaad Abbas127 reputationPosted Mar 30, 2015, 10:19 PM EDT
/*Here 'objdal' of which object where its declared??*/
Khargesh RajputRank #616 · 3.9K reputationPosted Mar 30, 2015, 10:34 PM EDT
Ds = objdal.FillDataSet(CommandType.StoredProcedure, "sp_getTopic");
for a example to show to bind dataset
you have to write your query/procedure to bind dataset
I was using DAL class and methods to fill dataset from database and bind dataset to gridview
Azaad Abbas127 reputationPosted Mar 30, 2015, 10:38 PM EDT
connection.Open();
command = new SqlCommand();
command.CommandText = "sp_Get_CustInfoSerach";
command.CommandType = CommandType.StoredProcedure;
command.Connection = connection;
command.Parameters.AddWithValue("@PageIndex", pageIndex);
command.Parameters.AddWithValue("@PageSize", int.Parse(ddlPaging.SelectedValue));
command.Parameters.Add("@RecordCount", SqlDbType.Int, 4);
command.Parameters["@RecordCount"].Direction = ParameterDirection.Output;
SqlParameter outParam = command.Parameters.Add("@bal", SqlDbType.Float);
outParam.Direction = ParameterDirection.Output;
SqlDataAdapter daAcc = new SqlDataAdapter(command);
DataSet dsAcc = new DataSet();
daAcc.Fill(dsAcc);
Khargesh RajputRank #616 · 3.9K reputationPosted Mar 30, 2015, 10:43 PM EDT
DataSet dsAcc = new DataSet();
you have created object here
instead you
declare dataset globally in viewstate as
public DataSet Ds
{
get
{
object temp = ViewState["Ds"];
return temp == null ? null : temp as DataSet;
}
set
{
ViewState["Ds"] = value;
}
}
Azaad Abbas127 reputationPosted Mar 30, 2015, 10:59 PM EDT
Khargesh RajputRank #616 · 3.9K reputationPosted Mar 31, 2015, 12:06 AM EDT
You can try to check
otherwise use dataset
Azaad Abbas127 reputationPosted Mar 31, 2015, 12:19 AM EDT
but here for paging need IDataReader coz its coming from sql query if bind dataset then cant do paging.
Khargesh RajputRank #616 · 3.9K reputationPosted Mar 31, 2015, 12:36 AM EDT
Azaad Abbas127 reputationPosted Mar 31, 2015, 12:45 AM EDT
Khargesh RajputRank #616 · 3.9K reputationPosted Mar 31, 2015, 12:58 AM EDT
and on event OnPageIndexChanging
grdSearch.PageIndex = e.NewPageIndex;
fncBindGrid();// this is function where You write the code on page load to bind gridview
Azaad Abbas127 reputationPosted Mar 31, 2015, 12:59 AM EDT
Azaad Abbas127 reputationPosted Apr 4, 2015, 4:16 AM EDT
public DataSet Ds
Khargesh RajputRank #616 · 3.9K reputationPosted Apr 4, 2015, 4:43 AM EDT
Gowtham RajamanickamRank #57 · 29K reputationPosted Apr 4, 2015, 9:31 PM EDT
Dawood AbbasRank #6,413 · 267 reputationPosted Apr 5, 2015, 9:25 PM EDT
Dawood AbbasRank #6,413 · 267 reputationPosted Apr 5, 2015, 9:43 PM EDT
Khargesh RajputRank #616 · 3.9K reputationPosted Apr 5, 2015, 10:04 PM EDT
Azaad Abbas127 reputationPosted Apr 5, 2015, 10:07 PM EDT
Azaad Abbas127 reputationPosted Apr 14, 2015, 1:10 AM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts