Click here to Skip to main content
15,889,739 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have designed the Gridview as below...
XML
<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>





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");
}
Posted
Updated 18-Jul-14 20:50pm
v5
Comments
KaushalJB 18-Jul-14 7:24am    
So whats your result coming while redirecting to testing.aspx ?
M.Thiyagaraja 18-Jul-14 9:38am    
It displays the result horizontally.
As like below.
Organization | Address | Phone | Email
M.Thiyagaraja 18-Jul-14 9:45am    
I want to grouped all the columns in the GridView, and then ,

I need to show the result as below

Organization
Address
Phone
Email

Consider i have 4 selected records, All the 4 records must want to display in the above manner(In Simple words as like DataList)
M.Thiyagaraja 19-Jul-14 2:29am    
Suppose Org_id=1 means , the corresponding id details(such as Org Name, Address,Phone,Email) wants to retrieve vertically. in next cell, selected id (checkbox)details should be display as like Org_id=1.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900