I have an ASP.NET page that contains textboxes, dropdownlists and a gridview. There are two ways to fill in the form, one is when a user selects a row from the gridview the values from the cells populate the textboxes and dropdownlists, the other is the user can directly enter the data into the form. This helps in adding, deleting and updating records from my database. My dropdownlists and gridview are populated with values from a sql statement on the page load event...
DROPDOWNLIST:
dt = dal.FillDataTable(dbType.SqlServer, "SELECT V_VendorNo + ' | ' + V_VendorName FROM VendorTbl")
ddlVendorEncum.DataSource = dt
ddlVendorEncum.DataTextField = dt.Columns.Item(0).ToString
ddlVendorEncum.DataValueField = dt.Columns.Item(0).ToString
ddlVendorEncum.DataBind()
GRIDVIEW:
dts = dal.ExecuteSelectStoredPro(dbType.SqlServer, "EncumBugSearch", "@year", lblDef_FY.Text)
gvEncumbered.DataSource = dts
gvEncumbered.DataBind()
Because the dropdownlist is a concatentation of two columns from my table, when I select a row in my gridview the value will not populate the dropdownlist with the selected value. Is there a way to do a reverse type concatenation to get the dropdownlist to populate? I tried this:
ddlVendorEncum.Text = gvEncumbered.SelectedRow.Cells(1).ToString
which is the way I populate the textboxes but I get an error.