none
怎样在意个GRIDVIEW里面单击后。另外一个GRIDVIEW内容跟着变。 RRS feed

  • 问题

  • 在人数列单击后右边根据左边被单击行的序号显示数据。当然如果右边那个GRIDVIEW能够跟着被单击行变化位置和显示和隐藏就更好了。

    求实例或者解决办法。

    <table  cellspacing="1">
                    <tr>
                        <td>
                        <div>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                DataKeyNames="序号" DataSourceID="SqlDataSource1" 
                onrowcreated="GridView1_RowCreated" onrowdatabound="GridView1_RowDataBound" 
                                onselectedindexchanged="GridView1_SelectedIndexChanged">
                <Columns>
                    <asp:CommandField ShowEditButton="True" />
                    <asp:BoundField DataField="序号" HeaderText="序号" ReadOnly="True" 
                        SortExpression="序号" />
                    <asp:BoundField DataField="日期" HeaderText="日期" SortExpression="日期" />
                    <asp:BoundField DataField="客户" HeaderText="客户" SortExpression="客户" />
                    <asp:BoundField DataField="模具编号" HeaderText="模具编号" SortExpression="模具编号" />
                    <asp:BoundField DataField="成套" HeaderText="成套" SortExpression="成套" />
                    <asp:BoundField DataField="分开" HeaderText="分开" SortExpression="分开" />
                    <asp:BoundField DataField="毛边" HeaderText="毛边" SortExpression="毛边" />
                    <asp:BoundField DataField="脏污" HeaderText="脏污" SortExpression="脏污" />
                    <asp:BoundField DataField="裁切" HeaderText="裁切" SortExpression="裁切" />
                    <asp:BoundField DataField="数量" HeaderText="数量" SortExpression="数量" />
                    <asp:BoundField DataField="完成包数" HeaderText="完成包数" SortExpression="完成包数" />
                    <asp:BoundField DataField="开始" HeaderText="开始" SortExpression="开始" />
                    <asp:BoundField DataField="结束" HeaderText="结束" SortExpression="结束" />
                    <asp:BoundField DataField="平均时间" HeaderText="平均时间" SortExpression="平均时间" />
                    <asp:BoundField DataField="平均每人" HeaderText="平均每人" SortExpression="平均每人" />
                    <asp:BoundField DataField="金额" HeaderText="金额" SortExpression="金额" />
                    <asp:BoundField DataField="组别" HeaderText="组别" SortExpression="组别" />
                    <asp:TemplateField HeaderText="人数" SortExpression="人数">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("人数") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Bind("人数") %>' 
                                onclick="LinkButton1_Click" CommandName="Select" >LinkButton</asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:TEST2ConnectionString %>" 
                DeleteCommand="DELETE FROM [包装日报表] WHERE [序号] = @序号" 
                InsertCommand="INSERT INTO [包装日报表] ([序号], [日期], [客户], [模具编号], [成套], [分开], [毛边], [脏污], [裁切], [数量], [完成包数], [开始], [结束], [平均时间], [平均每人], [金额], [组别], [人数]) VALUES (@序号, @日期, @客户, @模具编号, @成套, @分开, @毛边, @脏污, @裁切, @column1, @完成包数, @开始, @结束, @平均时间, @平均每人, @金额, @组别, @人数)" 
                SelectCommand="SELECT * FROM [包装日报表]" 
                
                UpdateCommand="UPDATE [包装日报表] SET [日期] = @日期, [客户] = @客户, [模具编号] = @模具编号, [成套] = @成套, [分开] = @分开, [毛边] = @毛边, [脏污] = @脏污, [裁切] = @裁切, [数量] = @column1, [完成包数] = @完成包数, [开始] = @开始, [结束] = @结束, [平均时间] = @平均时间, [平均每人] = @平均每人, [金额] = @金额, [组别] = @组别, [人数] = @人数 WHERE [序号] = @序号">
                <DeleteParameters>
                    <asp:Parameter Name="序号" Type="Int64" />
                </DeleteParameters>
                <InsertParameters>
                    <asp:Parameter Name="序号" Type="Int64" />
                    <asp:Parameter Name="日期" Type="String" />
                    <asp:Parameter Name="客户" Type="String" />
                    <asp:Parameter Name="模具编号" Type="String" />
                    <asp:Parameter Name="成套" Type="String" />
                    <asp:Parameter Name="分开" Type="String" />
                    <asp:Parameter Name="毛边" Type="String" />
                    <asp:Parameter Name="脏污" Type="String" />
                    <asp:Parameter Name="裁切" Type="String" />
                    <asp:Parameter Name="column1" Type="String" />
                    <asp:Parameter Name="完成包数" Type="String" />
                    <asp:Parameter Name="开始" Type="String" />
                    <asp:Parameter Name="结束" Type="String" />
                    <asp:Parameter Name="平均时间" Type="String" />
                    <asp:Parameter Name="平均每人" Type="String" />
                    <asp:Parameter Name="金额" Type="String" />
                    <asp:Parameter Name="组别" Type="String" />
                    <asp:Parameter Name="人数" Type="String" />
                </InsertParameters>
                <UpdateParameters>
                    <asp:Parameter Name="日期" Type="String" />
                    <asp:Parameter Name="客户" Type="String" />
                    <asp:Parameter Name="模具编号" Type="String" />
                    <asp:Parameter Name="成套" Type="String" />
                    <asp:Parameter Name="分开" Type="String" />
                    <asp:Parameter Name="毛边" Type="String" />
                    <asp:Parameter Name="脏污" Type="String" />
                    <asp:Parameter Name="裁切" Type="String" />
                    <asp:Parameter Name="column1" Type="String" />
                    <asp:Parameter Name="完成包数" Type="String" />
                    <asp:Parameter Name="开始" Type="String" />
                    <asp:Parameter Name="结束" Type="String" />
                    <asp:Parameter Name="平均时间" Type="String" />
                    <asp:Parameter Name="平均每人" Type="String" />
                    <asp:Parameter Name="金额" Type="String" />
                    <asp:Parameter Name="组别" Type="String" />
                    <asp:Parameter Name="人数" Type="String" />
                    <asp:Parameter Name="序号" Type="Int64" />
                </UpdateParameters>
            </asp:SqlDataSource>
        
        </div>
                            </td>
                        <td>
                            <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" 
                                DataKeyNames="序号" DataSourceID="SqlDataSource3">
                                <Columns>
                                    <asp:CommandField ShowEditButton="True" />
                                    <asp:BoundField DataField="序号" HeaderText="序号" InsertVisible="False" 
                                        ReadOnly="True" SortExpression="序号" />
                                    <asp:BoundField DataField="日报序号" HeaderText="日报序号" SortExpression="日报序号" />
                                    <asp:BoundField DataField="组别" HeaderText="组别" SortExpression="组别" />
                                    <asp:BoundField DataField="姓名" HeaderText="姓名" SortExpression="姓名" />
                                </Columns>
                            </asp:GridView>
                            <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
                                ConnectionString="<%$ ConnectionStrings:TEST2ConnectionString %>" 
                                DeleteCommand="DELETE FROM [包装参与人员表] WHERE [序号] = @序号" 
                                InsertCommand="INSERT INTO [包装参与人员表] ([日报序号], [组别], [姓名]) VALUES (@日报序号, @组别, @姓名)" 
                                SelectCommand="SELECT * FROM [包装参与人员表]" 
                                UpdateCommand="UPDATE [包装参与人员表] SET [日报序号] = @日报序号, [组别] = @组别, [姓名] = @姓名 WHERE [序号] = @序号">
                                <DeleteParameters>
                                    <asp:Parameter Name="序号" Type="Int64" />
                                </DeleteParameters>
                                <InsertParameters>
                                    <asp:Parameter Name="日报序号" Type="String" />
                                    <asp:Parameter Name="组别" Type="String" />
                                    <asp:Parameter Name="姓名" Type="String" />
                                </InsertParameters>
                                <UpdateParameters>
                                    <asp:Parameter Name="日报序号" Type="String" />
                                    <asp:Parameter Name="组别" Type="String" />
                                    <asp:Parameter Name="姓名" Type="String" />
                                    <asp:Parameter Name="序号" Type="Int64" />
                                </UpdateParameters>
                            </asp:SqlDataSource>
                            </td>
                    </tr>
                </table>

     protected void LinkButton1_Click(object sender, EventArgs e)
        {
            
            SqlDataSource2.SelectCommand = "select * from 包装人员表 where 组别='" + DropDownList1.SelectedValue + "'";   
        }

    2012年5月21日 12:26

答案

  • 对不起,手动写最好:)

    比如(只是一个比方,请根据实际情况自行修改):

     <asp:SqlDataSource
              id="SqlDataSource1"
              runat="server"
              DataSourceMode="DataReader"
              ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
              SelectCommand="SELECT FirstName, LastName, Title FROM Employees where id=@id">
           <SelectParameters>
              <aspControl:Parameter Name="id" PropertyText="SelectedValue" ControlId="GridView1" Type="String"/>
           </SelectParameters>
          </asp:SqlDataSource>


       QQ我:讨论(Talk)
    下载MSDN桌面工具(Vista,Win7)
    我的博客园
    慈善点击,点击此处

    • 已标记为答案 彭123 2012年5月22日 7:08
    2012年5月22日 2:46

全部回复