Asp.net 在dropdownlist中使用类增量运算符
我有一个名为Asp.net 在dropdownlist中使用类增量运算符,asp.net,drop-down-menu,Asp.net,Drop Down Menu,我有一个名为MonthDropDownList的下拉列表,由sql数据源限定的月份组成。 现在我想访问MonthDropDownList的值 MonthDropDownList.selecteditem++. 所以 我怎样才能做到这一点 这是我的密码 DataClassesDataContext db = null; db = new DataClassesDataContext(); tblAdvance advance = new tblAdvance(); ad
MonthDropDownList
的下拉列表,由sql数据源限定的月份组成。
现在我想访问MonthDropDownList的值
MonthDropDownList.selecteditem++.
所以
我怎样才能做到这一点
这是我的密码
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);
创建月数组
使用它的索引每月添加一次
string[] months = new string[] {"January", "February", "March", "April", "May",
"June", "July", "August", "September", "October", "November", "December"};
假设您有一个id为dd1的dropdownlist
,值为0,1,2,…
如果您需要查找二月
,并且您有值1
,则可以这样做
int current month=1;
string nextmonth=months[current+1];
好的,如果您有两个下拉列表,在几个月内充当上限和下限,那么SelectedValue++函数将如下所示(VB.NET):
这将返回列表中的下一个月,除非“下限”列表中的月份等于或大于“上限”列表中的月份,在这种情况下,它只返回上限月份
这就是你的意思,还是你需要递归的东西?我用这段代码找到了答案。这很简单,但可能是我觉得问题太复杂了
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();
}
}
DataClassesDataContext db=null;
db=新的DataClassesDataContext();
tblAdvance advance=新的tblAdvance();
advance.StudentID=Convert.ToInt32(StudentNameDropDownList.SelectedValue);
advance.FromMonth=FromMonthDropDownList.SelectedItem.Value;
advance.UptoMonth=tomonthropdownlist.SelectedItem.Value;
advance.AdvanceAmount=Convert.ToInt32(txtdvanceamount.Text);
advance.RollNo=Convert.ToInt32(txtRollNo.Text);
db.tblAdvances.INSERTONSUPMIT(预付款);
db.SubmitChanges();
db.Connection.Close();
db.Dispose();
int k=FromMonthDropDownList.SelectedIndex;
int l=ToMonthDropDownList.SelectedIndex;
对于(int i=k;简单地说,我有两个下拉列表,上面的月份和下面的月份。然后我有一个循环,如果我把上面的月份放在一月,下面的月份放在三月,那么上面的月份++应该是二月,上面的月份++必须暗示marchIn简单的单词,上面的月份和下面的月份是两个下拉列表。然后我有一个循环其中,如果我把上个月放在一月,下个月放在三月,那么上个月++应该是二月,上个月++必须是三月…这是我的实际需求@Shekhar
int current month=1;
string nextmonth=months[current+1];
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
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();
}
}