Home > DeveloperSection > Forums > How to display data in gridview on click?
Ankit Singh

Total Post:341

Points:2389
Posted on    November-13-2014 10:32 PM

 ASP.Net C#  Gridview 
Ratings:


 1 Reply(s)
 608  View(s)
Rate this:

I have a gridview that becomes quite long with some information that could be somewhat hidden.

Here's my asp:

<asp:GridView ID="gvLogBody" runat="server" CssClass="Grid" AllowPaging="true" AllowSorting="true" PageSize="10" AutoGenerateColumns="true">

</asp:GridView>

And here's my code behind:

DataSet ds = new DataSet();

ds.Tables.Add("LogBody");

ds.Tables["LogBody"].Columns.Add("timeStamp");

ds.Tables["LogBody"].Columns.Add("name");

ds.Tables["LogBody"].Columns.Add("message");

foreach (LogObject l in logLines)

{

    ds.Tables["LogBody"].Rows.Add(l.TimeStamp, l.Name, l.Message);

}

gvLogBody.DataSource = ds.Tables["LogBody"].DefaultView;

gvLogBody.DataBind();

This gives me a gridview that looks like this: ____________________________________________________________________________________________

|timeStamp|                      name                     |            message             |

+---------+-----------------------------------------------+--------------------------------+

|01-01-01 | someLongAndQuiteUnnecesaryNameThatIWishToHide | someMessageThatIsMoreImportant |

+---------+-----------------------------------------------+--------------------------------+

What I want is something like this:

_________________________________________________________

|timeStamp|    name     |            message             |

+---------+-------------+--------------------------------+

|01-01-01 | clickToShow | someMessageThatIsMoreImportant |

+---------+-------------+--------------------------------+

And once the user clicks the text, it expands / opens a popup or something.

How can this be done?



Tanuj Kumar

Total Post:134

Points:940
Posted on    November-14-2014 1:56 AM

This piece of code will help you out.

<asp:GridView ID="gvLogBody" runat="server" CssClass="Grid" AllowPaging="true" AllowSorting="true" PageSize="10" AutoGenerateColumns="false">

                    <Columns>

                        <asp:BoundField DataField="timeStamp" HeaderText="timeStamp" />

                        <asp:TemplateField HeaderText="name">

                            <ItemTemplate>

                                <input type="button" value="clickToShow" onclick="alert('<%#Eval("name") %>')" />

                            </ItemTemplate>

                        </asp:TemplateField>

                        <asp:BoundField DataField="message" HeaderText="message" />

                    </Columns>

                </asp:GridView>


Don't want to miss updates? Please click the below button!

Follow MindStick