您的位置:首页 > 大数据 > 人工智能

关于GridView,DetailsView,DropDownList1

2010-08-25 12:19 309 查看
谁可以帮我解决下的

我在GridView的EmptyDataTemplate里放一个DetailsView,DropDownList DropDownList用于获取ID值 DetailsView用做于插入数据 不过DetailsView的ID值要在DropDownList里获取的 怎么样获取DropDownList的值 能详细点的 有代码。。。

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:GeDaiSystem %>"
SelectCommand="SELECT a.ID, a.Name, a.Agent, a.DelegationAmount, a.NewBalance, a.DelegationUnit, a.CaseStatus, a.CaseType, a.AdjustmentCity FROM GeDai a INNER JOIN Legal_services b ON a.P_ID = b.ID"
UpdateCommand="UPDATE GeDai SET Name = @Name, Agent = @Agent, DelegationAmount = @DelegationAmount, NewBalance = @NewBalance, DelegationUnit = @DelegationUnit, CaseStatus = @CaseStatus, CaseType = @CaseType, AdjustmentCity = @AdjustmentCity WHERE (ID=@ID)"
InsertCommand="insert into GeDai(legalstatus,Name,Address,TEl,Note,FinalTime,Agent,ArchiveTime,ArchiveManage,ArchiveNo,DelegationAmount,NewBalance,DelegationUnit,CaseStatus,CaseType,AdjustmentCity)values(@legalstatus,@Name,@Address,@TEl,@Note,@FinalTime,@Agent,@ArchiveTime,@ArchiveManage,@ArchiveNo,@DelegationAmount,@NewBalance,@DelegationUnit,@CaseStatus,@CaseType,@AdjustmentCity)"
DeleteCommand="DELETE FROM GeDai WHERE (ID=@ID)">
<InsertParameters>
<asp:Parameter Name="legalstatus" />
<asp:Parameter Name="Name" />
<asp:Parameter Name="Address" />
<asp:Parameter Name="TEl" />
<asp:Parameter Name="Note" />
<asp:Parameter Name="FinalTime" />
<asp:Parameter Name="Agent" />
<asp:Parameter Name="ArchiveTime" />
<asp:Parameter Name="ArchiveManage" />
<asp:Parameter Name="ArchiveNo" />
<asp:Parameter Name="DelegationAmount" />
<asp:Parameter Name="NewBalance" />
<asp:Parameter Name="DelegationUnit" />
<asp:Parameter Name="CaseStatus" />
<asp:Parameter Name="CaseType" />
<asp:Parameter Name="AdjustmentCity" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Name" />
<asp:Parameter Name="Agent" />
<asp:Parameter Name="DelegationAmount" />
<asp:Parameter Name="NewBalance" />
<asp:Parameter Name="DelegationUnit" />
<asp:Parameter Name="CaseStatus" />
<asp:Parameter Name="CaseType" />
<asp:Parameter Name="AdjustmentCity" />
<asp:Parameter Name="id" />
</UpdateParameters>
<DeleteParameters>
<asp:Parameter Name="id" />
</DeleteParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="SqlDataSource1" OnRowCommand="GridView1_RowCommand" Width="762px">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
SortExpression="ID" />
<asp:BoundField DataField="Name" HeaderText="名称" SortExpression="Name" />
<asp:BoundField DataField="Agent" HeaderText="经办人" SortExpression="Agent" />
<asp:BoundField DataField="DelegationAmount" HeaderText="委托金额" SortExpression="DelegationAmount" />
<asp:BoundField DataField="NewBalance" HeaderText="最新余额" SortExpression="NewBalance" />
<asp:BoundField DataField="DelegationUnit" HeaderText="委托单位" SortExpression="DelegationUnit" />
<asp:BoundField DataField="CaseStatus" HeaderText="案件状态" SortExpression="CaseStatus" />
<asp:BoundField DataField="CaseType" HeaderText="案件类型" SortExpression="CaseType" />
<asp:BoundField DataField="AdjustmentCity" HeaderText="调整城市" SortExpression="AdjustmentCity" />
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:ButtonField CommandName="Insert" Text="增加" />
</Columns>
<EmptyDataTemplate>
   
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"
DataTextField="CompanyName" DataValueField="ID">
</asp:DropDownList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:GeDaiSystem %>"
SelectCommand="SELECT [ID], [CompanyName] FROM [Legal_services]"></asp:SqlDataSource>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="id" DataSourceID="SqlDataSource1" DefaultMode="Insert" Height="47px"
OnItemInserted="DetailsView1_ItemInserted" OnPageIndexChanging="DetailsView1_PageIndexChanging"
Width="600px">
<Fields>
<asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True"
SortExpression="id" />
<asp:BoundField DataField="Name" HeaderText="名称" SortExpression="Name" />
<asp:BoundField DataField="legalstatus" HeaderText="法律单位地位" SortExpression="legalstatus" />
<asp:BoundField DataField="Address" HeaderText="地址" SortExpression="Address" />
<asp:BoundField DataField="TEl" HeaderText="联系电话" SortExpression="TEl" />
<asp:BoundField DataField="Note" HeaderText="备注" SortExpression="registeredCapital" />
<asp:BoundField DataField="FinalTime" HeaderText="结案时间" SortExpression="FinalTime" />
<asp:BoundField DataField="Agent" HeaderText="经办人" SortExpression="Agent" />
<asp:BoundField DataField="ArchiveTime" HeaderText="归档时间(格式:1900-00-00)" SortExpression="ArchiveTime" />
<asp:BoundField DataField="ArchiveManage" HeaderText="归档管理员" SortExpression="ArchiveManage" />
<asp:BoundField DataField="ArchiveNo" HeaderText="档案号" SortExpression="ArchiveNo" />
<asp:BoundField DataField="DelegationAmount" HeaderText="委托金额" SortExpression="DelegationAmount" />
<asp:BoundField DataField="NewBalance" HeaderText="最新余额" SortExpression="NewBalance" />
<asp:BoundField DataField="DelegationUnit" HeaderText="委托单位" SortExpression="DelegationUnit" />
<asp:BoundField DataField="CaseStatus" HeaderText="案件状态" SortExpression="CaseStatus" />
<asp:BoundField DataField="CaseType" HeaderText="案件类型" SortExpression="CaseType" />
<asp:BoundField DataField="AdjustmentCity" HeaderText="调整城市" SortExpression="AdjustmentCity" />
<asp:CommandField ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
</EmptyDataTemplate>
</asp:GridView>

cs:

protected void Page_Load(object sender, EventArgs e)
{

}

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Insert")
{
GridView1.DataSourceID = "";
GridView1.DataBind();
string sql = "INSERT INTO GeDai(legalstatus, Name, Address, TEl, Note, FinalTime, Agent, ArchiveTime, ArchiveManage, ArchiveNo, DelegationAmount, NewBalance, DelegationUnit, CaseStatus, CaseType, AdjustmentCity)VALUES (@legalstatus, @Name, @Address, @TEl, @Note, @FinalTime, @Agent, @ArchiveTime, @ArchiveManage, @ArchiveNo, @DelegationAmount, @NewBalance, @DelegationUnit, @CaseStatus, @CaseType, @AdjustmentCity)";

//Repeater rep_downMenu = (Repeater)e.Item.FindControl("rep_downMenu");
}
}

protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
{
GridView1.DataSourceID = "SqlDataSource1";
GridView1.DataBind();

}

protected void DetailsView1_PageIndexChanging(object sender, DetailsViewPageEventArgs e)
{

}

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{

}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: