I have gridview with dropdownlist.
I
successfully added the dropdownlist values from sql server table1.
I have
another table contains the dropdownlist selected values previously, how can I show that saved values in the dropdownlost indeviually.(dropdownlist1.selectedindex = what I have in the database)?

The question in short: I can save the value from the dropdownlist, but I don't know how to show that value again on page load?
Gridview code
<asp:GridView ID="Grid_View1" runat="server" Font-Size="Large" CellPadding="3" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" OnRowCommand="Subjects_RowCommand" OnRowDataBound="Classes_List_RowDataBound" AutoGenerateColumns="False" \>
\<AlternatingRowStyle BorderWidth="1px" /\>
\<Columns\>
\<asp:TemplateField HeaderText="Monday"\>
\<ItemTemplate\>
\<asp:DropDownList ID="Monday" AppendDataBoundItems="true" runat="server" AutoPostBack="True" OnSelectedIndexChanged="Monday_SelectedIndexChanged"\>
\</asp:DropDownList\>
\</ItemTemplate\>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tuesday">
<ItemTemplate>
<asp:DropDownList ID="Tuesday" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Wednesday"></asp:TemplateField>
<asp:TemplateField HeaderText="Thursday"></asp:TemplateField>
<asp:TemplateField HeaderText="Friday"></asp:TemplateField>
</Columns>
<EditRowStyle BorderStyle="Solid" BorderWidth="1px" />
<EmptyDataRowStyle BorderStyle="Solid" BorderWidth="1px" />
<FooterStyle BorderStyle="Solid" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<PagerStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" />
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<SelectedRowStyle BorderStyle="Solid" />
<SortedAscendingCellStyle BackColor="#F4F4FD" />
<SortedAscendingHeaderStyle BackColor="#5A4C9D" />
<SortedDescendingCellStyle BackColor="#D8D8F0" />
<SortedDescendingHeaderStyle BackColor="#3E3277" />
</asp:GridView>
Select the information
protected void Page_Load(object sender, EventArgs e)
{
Sql_Connection.Open();
SqlCommand Select_Subject_R = new SqlCommand("SELECT SID,Period,Time,Monday,Tuesday,Wednesday,Thursday,Friday FROM \[OrisonSystemRAWAFED\].\[dbo\].\[CCE_Schedule\] where Academicyear =(select AcademicYear from School_AcademicYear where Status='Current') and Class='10' and Division='A'", Sql_Connection);
SqlDataAdapter sda = new SqlDataAdapter(Select_Subject_R);
DataTable dt = new DataTable();
sda.Fill(dt);
Sql_Connection.Close();
Grid_View1.DataSource = dt;
Grid_View1.DataBind();
}
Select the Subjects from Table1
protected void Classes_List_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string f = e.Row.Cells\[0\].Text;
SqlCommand cmd = new SqlCommand("SELECT TOP (100) PERCENT dbo.CCE_SubjectGroup.SubjectCode, dbo.CCE_SubjectMaster.SubjectName FROM dbo.CCE_SubjectGroup INNER JOIN dbo.CCE_SubjectMaster ON dbo.CCE_SubjectGroup.SubjectCode = dbo.CCE_SubjectMaster.SubjectCode WHERE (dbo.CCE_SubjectGroup.AcademicYear = (select AcademicYear from School_AcademicYear where Status='Current')) AND (dbo.CCE_SubjectGroup.Class = '10') GROUP BY dbo.CCE_SubjectGroup.SubjectCode, dbo.CCE_SubjectMaster.SubjectName ORDER BY dbo.CCE_SubjectGroup.SubjectCode", Sql_Connection);
cmd.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count != 0)
{
DropDownList DropDownList1 = (DropDownList)e.Row.FindControl("Monday");
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "SubjectName";
DropDownList1.DataValueField = "SubjectCode";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem("", "0"));
DropDownList1 = (DropDownList)e.Row.FindControl("Tuesday");
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "SubjectName";
DropDownList1.DataValueField = "SubjectCode";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem("", "0"));
DropDownList ddl = new DropDownList();
foreach (GridViewRow row in Grid_View1.Rows)
{
ddl = (DropDownList)row.FindControl("Monday");
ddl.SelectedIndex = 2;
}
}
}
When I change the Selectedindex manually, it change it for all rows
DropDownList ddl = new DropDownList();
foreach (GridViewRow row in Grid_View1.Rows)
{
ddl = (DropDownList)row.FindControl("Monday");
ddl.SelectedIndex = 2;
}