How Can I Update A Gridview With 2 Parameters?
I'm new to this and maybe doing things wrong. I'm trying to produce a filtered view using 2 different parameters. When I pass in one parameter my code works
Solution 1:
just add the type of the parameter in the aspx:
<asp:Parameter ControlID="ReportListItemsLb" Name="reportgroupid" PropertyName="SelectedValue"type="DateTime"></asp:Parameter>
Solution 2:
Try this out.
1.Create a method which will return db null if parameter is not passed in the stored procedure
publicstaticobject GetDataValue(object o)
{
if (o == null || String.Empty.Equals(o))
return DBNull.Value;
elsereturn o;
}
2.Create a method which will called the stored procedure and fill the dataset.
public DataSet GetFillGvds(string param_1, string param_2) {
try
{
DataSet oDS = new DataSet();
SqlParameter[] oParam = new SqlParameter[2];
oParam[0] = new SqlParameter("@Param1", GetDataValue(param_1));
oParam[1] = new SqlParameter("@Param1", GetDataValue(param_2));
oDS = SqlHelper.ExecuteDataset(DataConnectionString, CommandType.StoredProcedure, "spTest", oParam);
return oDS;
}
catch (Exception e)
{
ErrorMessage = e.Message;
returnnull;
}
}
Create a dataset to bind data in the gridview. For instance,
DataSetFillGvds=newDataSet();
param1FillGvds = "param1";
param2FillGvds = "";
FillGvds = GetFillGvds();// Assuming you have created the method to fill the dataset.if(FillGvds != null)
{
if(FillGvds.Tables[0].Rows.Count > 0)
{
GridView1.Datasource = FillGvds;
GridView1.DataBind();
label1.Text = Convert.ToString(FillGvds.Tables[0].Rows.Count);
}
}
In order to pass the db null you query should be like this.
SELECT *(whatever you want)
FROM YourTableName
WHEREcolName1= COALESCE(@colName1, colName1) ANDcolName2= COALESCE(@colName2,colName2)
Post a Comment for "How Can I Update A Gridview With 2 Parameters?"