本文介绍了当我在Gridview中选择复选框时,我必须在另一个Gridview中显示结果。这应该像Asp.Net中的Datalist Control一样显示结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Gridview设计如下......

I have designed the Gridview as below...

<asp:GridView ID="GV_Test" runat="server" AutoGenerateColumns="false">
                <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <table>
                                <tr>
                                    <td colspan="2" align="center">
                                        <asp:CheckBox ID="chk" runat="server" AutoPostBack="true" OnCheckedChanged="chk_CheckedChanged" /></td>
                                </tr>
                                <tr>
                                    <td align="left"><strong>Organization :</strong><asp:Label ID="lbl_Org" runat="server" Text='<%#Eval("Name") %>'></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="left"><strong>Address :</strong><asp:Label ID="lbl_address" runat="server" Text='<%#Eval("Addres") %>'></asp:Label>



                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2" align="left"></td>
                                </tr>
                                <tr>
                                    <td align="left"><strong>Phone :</strong><asp:Label ID="lbl_Phone" runat="server" Text='<%#Eval("Phone") %>'></asp:Label>
                                </tr>

                                <tr>
                                    <td align="left"><strong>Email :</strong><asp:Label ID="lbl_Email" runat="server" Text='<%#Eval("Email") %>'></asp:Label>
                                </tr>

                            </table>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>











我需要垂直显示结果,gridview中所选行的所有列应组合在一起然后垂直显示当我选中GridView中的复选框时,简单来说,我必须在下一页中将结果显示为DataList。



当我按照下面的代码输出时,输出已经升级了。



protected void Btn_REsult_Click(object发件人,EventArgs e)

{

DataTable dt = new DataTable();

dt.Columns.Add(Organization,typeof( string));

dt.Columns.Add(Address,typeof(string));

dt.Columns.Add(Phone,typeof(string) );

dt.Columns.Add(Email,typeof(string));



in t len = GV_Test.Rows.Count;

for(int i = 0;我< LEN; i ++)

{

CheckBox chk =(CheckBox)GV_Test.Rows [i] .FindControl(chk);

Label lbl_Org = (标签)GV_Test.Rows [i] .FindControl(lbl_Org);

标签lbl_address =(标签)GV_Test.Rows [i] .FindControl(lbl_address);

Label lbl_Phone =(Label)GV_Test.Rows [i] .FindControl(lbl_Phone);

Label lbl_Email =(Label)GV_Test.Rows [i] .FindControl(lbl_Email) ;



if(chk.Checked)

{

DataRow row = dt.NewRow();

row [Organization] = Convert.ToString(lbl_Org.Text);

row [Address] = Convert.ToString(lbl_address.Text);

row [Phone] = Convert.ToString(lbl_Phone.Text);

row [Email] = Convert.ToString(lbl_Email.Text);



dt.Rows.Add(row);







}

}

会话[Res] = dt;

Response.Redirect (testing.aspx);

}






I need to display the result vertically, all the columns of the the selected row in the gridview should be grouped together and then display vertically When i select the check box in the GridView, in simple words i have to show the result as like DataList in next page.

The output has come horizotally when i follow the below code..

protected void Btn_REsult_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("Organization", typeof(string));
dt.Columns.Add("Address", typeof(string));
dt.Columns.Add("Phone", typeof(string));
dt.Columns.Add("Email", typeof(string));

int len = GV_Test.Rows.Count;
for (int i = 0; i < len; i++)
{
CheckBox chk = (CheckBox)GV_Test.Rows[i].FindControl("chk");
Label lbl_Org = (Label)GV_Test.Rows[i].FindControl("lbl_Org");
Label lbl_address = (Label)GV_Test.Rows[i].FindControl("lbl_address");
Label lbl_Phone = (Label)GV_Test.Rows[i].FindControl("lbl_Phone");
Label lbl_Email = (Label)GV_Test.Rows[i].FindControl("lbl_Email");

if (chk.Checked)
{
DataRow row = dt.NewRow();
row["Organization"] = Convert.ToString(lbl_Org.Text);
row["Address"] = Convert.ToString(lbl_address.Text);
row["Phone"] = Convert.ToString(lbl_Phone.Text);
row["Email"] = Convert.ToString(lbl_Email.Text);

dt.Rows.Add(row);



}
}
Session["Res"] = dt;
Response.Redirect("testing.aspx");
}

推荐答案

这篇关于当我在Gridview中选择复选框时,我必须在另一个Gridview中显示结果。这应该像Asp.Net中的Datalist Control一样显示结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 01:27