0

I'm having one grid and one link button on that grid which have rowcommand but whenever i click on that button it shows me error that there is no row at column 0. i've debugged whole code so many time but always it's showing me that there is no column even if there is data in that specific column of dataset. I'm new to asp.net as well as to sql so only knowing that how to put code but logic is not getting cleared please can anyone clear this query. your help is too much for me.

protected void grdManageBRProperty_RowCommand(object sender, GridViewCommandEventArgs e)
{
    Session["prptIdBRP"] = e.CommandArgument.ToString();
    string id = Session["prptIdBRP"].ToString();

    ds = obj.sel("select tblPropertyMaster.PropertyId,  tblPropertyTypeMaster.PropertyTypeName, tblSubPropertyTypeMaster.PropertySubTypeName, tblPropertyMaster.Floor, tblPropertyMaster.PlotArea, tblPropertyMaster.BuitUpArea, tblPropertyMaster.ExpectedAmount, tblCityMaster.CityName,  tblLocationMaster.LocationName, tblBuilderMaster.BuilderName, tblPropertyMaster.Description, tblPropertyMaster.Remarks, tblPropertyMaster.Furniture AS Furntr, tblPropertyMaster.IsAdvertise, tblPropertyMaster.Status, tblPropertyMaster.OwnerName, tblPropertyMaster.Address, tblPropertyMaster.ContactNo, tblPropertyMaster.MobileNo, tblPropertyMaster.EmailId from tblPropertyMaster INNER JOIN tblPropertyTypeMaster ON tblPropertyMaster.PropertyTypeId=tblPropertyTypeMaster.PropertyTypeId INNER JOIN tblSubPropertyTypeMaster ON tblPropertyMaster.PropertySubTypeId=tblSubPropertyTypeMaster.PropertySubTypeId INNER JOIN tblCityMaster ON tblPropertyMaster.CityId=tblCityMaster.CityId INNER JOIN tblLocationMaster ON tblPropertyMaster.LocationId=tblLocationMaster.LocationId INNER JOIN tblBuilderMaster ON tblPropertyMaster.BuilderName=tblBuilderMaster.BuilderId where tblPropertyMaster.PropertyId= '" + id + "'");
    string furn = ds.Tables[0].Rows[0]["Furntr"].ToString();

    if (furn == "True")
    {
        rbBRPFetchFurnitureYesC.Checked = true;
    }
    if (furn == "False")
    {
        rbBRPFetchFurnitureNoC.Checked = true;
    }

    string stts = ds.Tables[0].Rows[0]["Status"].ToString();
    if (stts == "True")
    {
        rbBRPFetchStatusSoldC.Checked = true;
    }
    if (stts == "False")
    {
        rbBRPFetchStatusNtSoldC.Checked = true;
    }

    string advrts = ds.Tables[0].Rows[0]["IsAdvertise"].ToString();
    if (advrts == "True")
    {
        rbBRPFetchIsAdYesC.Checked = true;
    }
    if (advrts == "False")
    {
        rbBRPFetchIsAdNoC.Checked = true;
    }

    ddlBRPFetchTypOfPrptC.SelectedItem.Text = ds.Tables[0].Rows[0]["PropertyTypeName"].ToString();
    ddlBRPFetchSbTypOfPrptC.SelectedItem.Text = ds.Tables[0].Rows[0]["PropertySubTypeName"].ToString();
    txtBRPFetchFloorC.Text = ds.Tables[0].Rows[0]["Floor"].ToString();
    txtBRPFetchPlotAreaC.Text = ds.Tables[0].Rows[0]["PlotArea"].ToString();
    txtBRPFetchBiultUpAreaC.Text = ds.Tables[0].Rows[0]["BuitUpArea"].ToString();
    txtBRPFetchAmountC.Text = ds.Tables[0].Rows[0]["ExpectedAmount"].ToString();
    ddlBRPFetchCityC.SelectedItem.Text = ds.Tables[0].Rows[0]["CityName"].ToString();
    ddlBRPFetchLocationC.SelectedItem.Text = ds.Tables[0].Rows[0]["LocationName"].ToString();
    ddlBRPFetchBuilderNameC.SelectedItem.Text = ds.Tables[0].Rows[0]["BuilderName"].ToString();
    txtBRPFetchDescC.Text = ds.Tables[0].Rows[0]["Description"].ToString();
    txtBRPFetchRemrksC.Text = ds.Tables[0].Rows[0]["Remarks"].ToString();
    txtBRPFetchOwnerNameC.Text = ds.Tables[0].Rows[0]["OwnerName"].ToString();
    txtBRPFetchAddressC.Text = ds.Tables[0].Rows[0]["Address"].ToString();
    txtBRPFetchConNumberC.Text = ds.Tables[0].Rows[0]["ContactNo"].ToString();
    txtBRPFetchMobNumberC.Text = ds.Tables[0].Rows[0]["MobileNo"].ToString();
    txtBRPFetchEmailC.Text = ds.Tables[0].Rows[0]["EmailId"].ToString();
    pnlBRPUpdateBySessionCriteria.Visible = true;
    pnlSearchBRPByDate.Visible = false;
    pnlBRPManageGrid.Visible = false;
}
Chiraag
  • 35
  • 10

1 Answers1

0

As a precautionary step always first check Rows are present and then only extract values from rows.

if(ds.Tables[0].Rows.Count > 0)
{
// Your code

}
Mudassir Hasan
  • 28,083
  • 20
  • 99
  • 133