0

MonthDropDownList我有一个名为由 sql 数据源限定的月份组成的下拉列表。现在我想访问MonthDropDownListlike的值

MonthDropDownList.selecteditem++. 

所以

if MonthDropDownList.selecteditem=January 
    then MonthDropDownList.selecteditem++=Febraury

我怎么能做到这一点???

这是我的代码

DataClassesDataContext db = null;
    db = new DataClassesDataContext();
    tblAdvance advance = new tblAdvance();
    advance.StudentID = Convert.ToInt32(StudentNameDropDownList.SelectedValue);
    advance.FromMonth = FromMonthDropDownList.SelectedItem.Value;
    advance.UptoMonth = ToMonthDropDownList.SelectedItem.Value;
    advance.AdvanceAmount = Convert.ToInt32(txtAdvanceAmount.Text);
    advance.RollNo = Convert.ToInt32(txtRollNo.Text);
    db.tblAdvances.InsertOnSubmit(advance);
    db.SubmitChanges();
    db.Connection.Close();
    db.Dispose();
    for (int i = FromMonthDropDownList.SelectedIndex; i <= ToMonthDropDownList.SelectedIndex;i++ )
    {
     DataClassesDataContext dc = null;
     dc = new DataClassesDataContext();
     tblTotalFee bill = new tblTotalFee();
     bill.StudentID = Convert.ToInt32(StudentNameDropDownList.SelectedValue);

bill.MonthName=FromMonthDropDownList.SelectedIndex[i]

        bill.DueFromPreviousMonth = 0;
        bill.ECAFee = 0;
        bill.HostelFee = 0;
        bill.LateFeeCharges = 0;
        bill.MonthlyFee = 0;
        bill.TransportFee = 0;
        bill.TotalFeeThisMonthAlongwithDueinthismonth=0;
        dc.tblTotalFees.InsertOnSubmit(bill);
        dc.SubmitChanges();
I want something like the blockquoted line
        dc.Connection.Close();
        dc.Dispose();
        }
4

3 回答 3

0

我用这段代码弄清楚了。这很简单,但可能我觉得问题太复杂了......

 DataClassesDataContext db = null;
    db = new DataClassesDataContext();
    tblAdvance advance = new tblAdvance();
    advance.StudentID = Convert.ToInt32(StudentNameDropDownList.SelectedValue);
    advance.FromMonth = FromMonthDropDownList.SelectedItem.Value;
    advance.UptoMonth = ToMonthDropDownList.SelectedItem.Value;
    advance.AdvanceAmount = Convert.ToInt32(txtAdvanceAmount.Text);
    advance.RollNo = Convert.ToInt32(txtRollNo.Text);
    db.tblAdvances.InsertOnSubmit(advance);
    db.SubmitChanges();
    db.Connection.Close();
    db.Dispose();
    int k = FromMonthDropDownList.SelectedIndex;
    int l = ToMonthDropDownList.SelectedIndex;
    for (int i = k; i <= l;i++ )
    {
        DataClassesDataContext dc = null;
        dc = new DataClassesDataContext();
        tblTotalFee bill = new tblTotalFee();
        bill.StudentID = Convert.ToInt32(StudentNameDropDownList.SelectedValue);
        bill.MonthName = FromMonthDropDownList.SelectedItem.Value;
        bill.DueFromPreviousMonth = 0;
        bill.ECAFee = 0;
        bill.HostelFee = 0;
        bill.LateFeeCharges = 0;
        bill.MonthlyFee = 0;
        bill.TransportFee = 0;
        bill.TotalFeeThisMonthAlongwithDueinthismonth=0;
        FromMonthDropDownList.SelectedIndex++;
        dc.tblTotalFees.InsertOnSubmit(bill);
        dc.SubmitChanges();
        dc.Connection.Close();
        dc.Dispose();
        }
}
于 2013-04-11T12:59:18.450 回答
0

创建一个月份数组,
使用它的索引来添加月份

string[] months = new string[] {"January", "February", "March", "April", "May",
         "June", "July", "August", "September", "October", "November", "December"};

假设你有一个dropdownlistiddd1和你有的值0,1,2,......

如果你需要找到February并且你有价值1,那么你可以这样做

int current month=1;
string nextmonth=months[current+1];
于 2013-04-11T12:06:26.587 回答
0

好的,所以如果您有两个下拉列表作为上限和下限运行几个月,那么您的 SelectedValue++ 函数将如下所示(VB.NET):

Public Function GetNextMonth(ByVal dd1 as DropDownList, Byval dd2 as DropDownList) as String
     If dd1.Items(dd1.SelectedIndex + 1).SelectedValue >= dd2.SelectedValue then
            Return dd2.SelectedItem.Text
     else
            Return dd1.Items(dd1.SelectedIndex + 1).Text
     end if
End Sub

这将返回列表中的下个月,除非“下限”列表中的月份等于或大于“上限”列表中的月份,在这种情况下,它只会返回上限月份。

这是你的意思,还是你需要一些递归的东西?

于 2013-04-11T12:08:51.580 回答