[Solved] ASP.Net Error: There is no row at position 0

Last Reply one month ago By pandeyism

Posted one month ago

i am facing this error when i select row and load into dropdownlist, null value is coming in dropdown 

 There is no row at position 0.

string SesnId1 = dm.GetData("select IDUOM from dbo.UOM where NameUOM='" + GVitem.SelectedRow.Cells[4].Text.Trim() + "'").Rows[0][0].ToString();

so how it will tackle...

protected void GVitem_SelectedIndexChanged(object sender, EventArgs e)
{
    txtID.Text = GVitem.SelectedRow.Cells[1].Text;
    txtnam.Text = GVitem.SelectedRow.Cells[2].Text;
    txtaltID.Text = GVitem.SelectedRow.Cells[6].Text;
    txtweight.Text = GVitem.SelectedRow.Cells[9].Text;
    string SesnId1 = dm.GetData("select IDUOM from dbo.UOM where NameUOM='" + GVitem.SelectedRow.Cells[4].Text.Trim() + "'").Rows[0][0].ToString();
    string SesnId2 = dm.GetData("select SecID from dbo.Sections where Secnam='" + GVitem.SelectedRow.Cells[7].Text.Trim() + "'").Rows[0][0].ToString();
    DDUOM.SelectedValue = SesnId1;

    string SesnId3 = dm.GetData("select TID from dbo.Item_Type where TName='" + GVitem.SelectedRow.Cells[5].Text.Trim() + "'").Rows[0][0].ToString();
    DDPack.SelectedValue = SesnId3;
    DDSec.SelectedValue = SesnId2;
    //DDUOM.SelectedItem.Text = GridView1.SelectedRow.Cells[4].Text;
    //DDPack.SelectedItem.Text = GVitem.SelectedRow.Cells[6].Text;
    txtbs.Text = GVitem.SelectedRow.Cells[3].Text;
    // DDPack.Items.Add(GVitem.SelectedRow.Cells[5].Text.ToString());
}

 

Posted one month ago Modified on one month ago

Hi akhter,

Take reference to below code make your changes.

Code

protected void GVitem_SelectedIndexChanged(object sender, EventArgs e)
{
    string SesnId1 = "";
    string SesnId2 = "";
    string SesnId3 = "";
    DataTable dt = dm.GetData("select IDUOM from dbo.UOM where NameUOM='" + GVitem.SelectedRow.Cells[4].Text.Trim() + "'");
    if (dt.Rows.Count > 0)
    {
        SesnId1 = dt.Rows[0][0].ToString();
    }
    DataTable dt2 = dm.GetData("select SecID from dbo.Sections where Secnam='" + GVitem.SelectedRow.Cells[7].Text.Trim() + "'");
    if (dt2.Rows.Count > 0)
    {
        SesnId2 = dt2.Rows[0][0].ToString();
    }

    DataTable dt3 = dm.GetData("select TID from dbo.Item_Type where TName='" + GVitem.SelectedRow.Cells[5].Text.Trim() + "'");
    if (dt3.Rows.Count > 0)
    {
        SesnId3 = dt3.Rows[0][0].ToString();
    }

    DDUOM.ClearSelection();
    DDUOM.Items.FindByText(SesnId1).Selected = true;

    DDPack.ClearSelection();
    DDPack.Items.FindByText(SesnId3).Selected = true;

    DDSec.ClearSelection();
    DDSec.Items.FindByText(SesnId2).Selected = true;
}