有两个表,一个主表,一个从表。如主表是一本杂志的相关信息,比如杂志名,出版社,杂志类别等信息,那么从表的信息就是这本杂志的具体的一本了,比如主表杂志是读者,那么这个从表信息就是读者2004年11月,价钱,重量等信息了。相对于主表中一本杂志,从表里可以有很多条记录,也就是说比如主表里的读者杂志,在从表里可以有从1月到12月的12条记录。
现在表态的问题是这样变态问题1------------我在一个DataGrid里面要先绑定出主表中所有的杂志,同时在这个DadaGrid的这一行后面绑定相应从表的记录,以一个DropDownList绑定。
DataGrid列字段(杂志名,出版社,杂志类别,期刊,价钱,重量)
其中的期刊就是DropDownList,是绑定了相应杂志名的所有从表记录。变态问题2-----------同时还需要实现,选择不同的DropDownList后,价钱,重量自动变成相应这一期的信息。如选择了读者2004年11月,那价钱,重量就是这一期的信息。变态问题3-----------DataGrid后面还需要加个CheckBox,把选中了的用循环将DataGrid记录插入到表中。如果可能的话可以点CheckBox后,DropDownList才能编辑,可下拉选择,CheckBox点取消后DropDownList不显示各位能提出思路和关键代码的都给分。觉得分少的可以留言,在开帖子送分!(本人表达能力不强,如有不明白的的地方可以加我[email protected])
现在表态的问题是这样变态问题1------------我在一个DataGrid里面要先绑定出主表中所有的杂志,同时在这个DadaGrid的这一行后面绑定相应从表的记录,以一个DropDownList绑定。
DataGrid列字段(杂志名,出版社,杂志类别,期刊,价钱,重量)
其中的期刊就是DropDownList,是绑定了相应杂志名的所有从表记录。变态问题2-----------同时还需要实现,选择不同的DropDownList后,价钱,重量自动变成相应这一期的信息。如选择了读者2004年11月,那价钱,重量就是这一期的信息。变态问题3-----------DataGrid后面还需要加个CheckBox,把选中了的用循环将DataGrid记录插入到表中。如果可能的话可以点CheckBox后,DropDownList才能编辑,可下拉选择,CheckBox点取消后DropDownList不显示各位能提出思路和关键代码的都给分。觉得分少的可以留言,在开帖子送分!(本人表达能力不强,如有不明白的的地方可以加我[email protected])
现在表态的问题是这样变态问题1------------我在一个DataGrid里面要先绑定出主表中所有的杂志,同时在这个DadaGrid的这一行后面绑定相应从表的记录,以一个DropDownList绑定。
DataGrid列字段(杂志名,出版社,杂志类别,期刊,价钱,重量)
其中的期刊就是DropDownList,是绑定了相应杂志名的所有从表记录。变态问题2-----------同时还需要实现,选择不同的DropDownList后,价钱,重量自动变成相应这一期的信息。如选择了读者2004年11月,那价钱,重量就是这一期的信息。变态问题3-----------DataGrid后面还需要加个CheckBox,把选中了的用循环将DataGrid记录插入到表中。如果可能的话可以点CheckBox后,DropDownList才能编辑,可下拉选择,CheckBox点取消后DropDownList不显示各位能提出思路和关键代码的都给分。觉得分少的可以留言,在开帖子送分!(本人表达能力不强,如有不明白的的地方可以加我[email protected])
呵呵开玩笑,难到是不难,因为我做过了,主要难的就是对后一个,你要记录每一步的操作,
做CHECK等
第一个:
ctype(e.item.cells(0).findcontrols("did"),dropdownlist).datasource=
bind第二个,给DROPDOWNLIST加一个事件委托:
For i = 0 To 9
AddHandler CType(dgListArticle.Items(i).Cells(5).FindControl("DropDownList1"), DropDownList).SelectedIndexChanged, AddressOf Selectchange
Next Private Sub Selectchange(ByVal sender As Object, ByVal e As System.EventArgs)
Dim drop As DropDownList
Dim s As String
Dim str As String
Dim arr As Array
Dim d As DataRow drop = CType(sender, DropDownList)
写你要做的事件
至于第三个:首先你要给DATASET加标志位,记录操作,例如删除,更新,还是追加最后你更新数据库就要按顺序更新
如果你用BUILD什么的,很难控制,譬如主键为一等等
这样容易以后用
如果你就用一次,那就没关系了
因为我们也做了
写了一个功能强大的DATAGRID基类。祝你好运定心点,很容易解决的
有问题问,用信息
邦定DataGrid里的DropDownList
http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=1975如何为DataGrid中编辑状态下的DropDownList写个SelectedIndexChanged事件
http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=23172
<asp:TemplateColumn >
<ItemTemplate>
<asp:label id="label1" runat="server" text='<%# DataBinder.Eval(Container, "DataItem.id")%>' />
</ItemTemplate>
</asp:TemplateColumn><asp:TemplateColumn HeaderText="特价分类">
<ItemTemplate>
<asp:DropDownList id="DropDownList1" runat="server" DataSource="<%# Getsource(e.) %>" DataTextField="name" DataValueField="id" />
</ItemTemplate>
</asp:TemplateColumn>.cs文件中写
protected DataSet Getsource()
{
Label label1 = (Label)DataGrid1.FindControl("Label")
_name=createdateset("select id,name from table1 where type="+label1.Text);
return _category;
}
而且你的.cs文件中写
protected DataSet Getsource()
{
Label label1 = (Label)DataGrid1.FindControl("Label")
_name=createdateset("select id,name from table1 where type="+label1.Text);
return _category;
}
也不能直接就这样写道Cs文件里吧。同时其他几个实现都没涉及?
DataGrid列字段(杂志名,出版社,杂志类别,期刊,价钱,重量)
其中的期刊就是DropDownList,是绑定了相应杂志名的所有从表记录。>第一个:
ctype(e.item.cells(0).findcontrols("did"),dropdownlist).datasource=
bind评论:这只是开始。主要工作是,在主表的itemdatabound中读到e.item.dataitem("杂志id"),然后以这个为参数调用store procedure或sql语句得到从表对应内容,绑定下拉框。
>>变态问题2-----------同时还需要实现,选择不同的DropDownList后,价钱,重量自动变成相应这一期的信息。如选择了读者2004年11月,那价钱,重量就是这一期的信息。>第二个,给DROPDOWNLIST加一个事件委托:
For i = 0 To 9
AddHandler CType(dgListArticle.Items(i).Cells(5).FindControl("DropDownList1"), DropDownList).SelectedIndexChanged, AddressOf Selectchange
Next Private Sub Selectchange(ByVal sender As Object, ByVal e As System.EventArgs)
Dim drop As DropDownList
Dim s As String
Dim str As String
Dim arr As Array
Dim d As DataRow drop = CType(sender, DropDownList)
写你要做的事件评论:这只是一个开头。
关键的困难是,要从每一行的dropdownlist的值绑定这一行。但是,在绑定的时候,这个dropdownlist是被清空的。
正确的做法是,在session中放一个datatable,在上面的代码之后,设定这个datatable:记下每个杂志选中了哪一期,然后重新绑定datagrid,绑定的时候,itemdatabound中再读这个datatable设定。>>变态问题3-----------DataGrid后面还需要加个CheckBox,把选中了的用循环将DataGrid记录插入到表中。如果可能的话可以点CheckBox后,DropDownList才能编辑,可下拉选择,CheckBox点取消后DropDownList不显示>至于第三个:
>首先你要给DATASET加标志位,记录操作,例如删除,更新,还是追加
>我建议你做一个DATAGRID,你可以继承DATAGIRD,
>这样容易以后用
>如果你就用一次,那就没关系了
>因为我们也做了
>写了一个功能强大的DATAGRID基类。祝你好运评论:继承datagrid的做法太复杂。简单的方法是上面说的datatable,逐行加入即可,只不过这个datatable应该有三列:杂志id,dropdownlist被选中期数,checkbox是否被选中。
我在一个DataGrid里面要先绑定出主表中所有的杂志,同时在这个DadaGrid的这一行后面绑定相应从表的记录,以一个DropDownList绑定。
DataGrid列字段(杂志名,出版社,杂志类别,期刊,价钱,重量)
其中的期刊就是DropDownList,是绑定了相应杂志名的所有从表记录。这个是先初始化的时候就把从表的信息查出来,还是选一个主表的信息后再查。
同时在DataGrid里面选了个DropDownList后怎么写触发事件。
AddHandler CType(dgListArticle.Items(i).Cells(5).FindControl("DropDownList1"), DropDownList).SelectedIndexChanged, AddressOf Selectchange
NextDROPDOWNLIST的事件委托
Private WithEvents tempdg As DataGrid Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
If Not Me.IsPostBack Then
Dim i As Int16
Dim sqlstr As String = "select * from book"
dg1.DataSource = da.ExecuteDataSet(sqlstr)
dg1.DataBind() For i = 0 To dg1.Items.Count - 1
sqlstr = "select * from subBook where b_id='" & CType(dg1.DataSource, DataSet).Tables(0).Rows(i)(0) & "'"
tempdg = CType(dg1.Items.Item(i).FindControl("Dg2"), DataGrid)
tempdg.DataSource = da.ExecuteDataSet(sqlstr)
tempdg.DataBind()
Next
End If
End Sub Private Sub tempdg_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles tempdg.ItemCommand
'......
End Sub
AddHandler CType(dgListArticle.Items(i).Cells(5).FindControl("DropDownList1"), DropDownList).SelectedIndexChanged, AddressOf Selectchange
NextDROPDOWNLIST的事件委托