Hey there,
I am not still sure about your problem, but here is what I think it is.
You want the DropDownLists of the column have a selected value from the
Datatype
Column of the DataTable that the GridView is binding from.
You can do two modifications and can make the selection this way:
Add a property
DataKeyNames
in this ListView like this:
<asp:listview id="listview1" runat="server" datakeynames="Datatype" xmlns:asp="#unknown"></asp:listview>
and add these lines inside
BindDataToGridviewDropdownlist
method:
ListViewDataItem di = (ListViewDataItem)list;
string dataType = listview1.DataKeys[di.DisplayIndex].Values[0].ToString();
ddf.SelectedValue = dataType;
here is how you
BindDataToGridviewDropdownlist
method would look like:
protected void BindDataToGridviewDropdownlist()
{
DataSet dsDept = new DataSet();
dsDept.ReadXml(Server.MapPath("XMLFile2.xml"));
DataView dv = dsDept.Tables[0].DefaultView;
foreach (var list in listview1.Items)
{
if (list.ItemType == ListViewItemType.DataItem)
{
DropDownList ddf = (DropDownList)list.FindControl("ddldatatype");
ddf.DataSource = dv;
ddf.DataTextField = "value";
ddf.DataBind();
ddf.Items.Insert(0, new ListItem("--Select--", "0"));
ListViewDataItem di = (ListViewDataItem)list;
string dataType = listview1.DataKeys[di.DisplayIndex].Values[0].ToString();
ddf.SelectedValue = dataType;
}
}
}
Let me know if it works or not, and most importantly this is what you wanted.
Azee...