2013-04-11 39 views
0

我有一個名爲MonthDropDownList的下拉列表,由sql數據源限定的月份組成。 現在我要訪問的MonthDropDownList值一樣在下拉列表中使用增量運算符

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(); 
     } 

回答

0

創造個月
數組 使用它的指數以獲得每月增加

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

假設你有一個dropdownlist id爲dd1和你有0,1,2,......

的值,如果你需要找到February,你纔有價值1那麼你可以做這樣的

int current month=1; 
string nextmonth=months[current+1]; 
+0

簡而言之,我有上月和下月作爲兩個下拉列表。然後我有一個循環裏面,如果我把上月作爲一月和下月作爲3月然後上月++應該febraury和再次uppermonth ++必須暗示行軍.....這是我的實際要求@Shekhar – 2013-04-11 12:18:16

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 

這將在列表中返回下個月,除非「下界」列表中的月份等於或大於「上界」列表中的月份,在這種情況下,它只會返回上限月份。

這是你的意思,還是你需要遞歸的東西?

+0

簡而言之,我有上作爲兩個下拉列表的月份和月份。然後我有一個循環,如果我把上月份作爲一月份和下月份作爲三月份,那麼上月份++應該是febraury,並且上月++又必須暗示進行 – 2013-04-11 12:17:49

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(); 
     } 
}