Not sure that I am clear with your clear inteions are, but you by any chance, meant to say you want to nest a table in a gridview, as I certainly would do that and add the controls dynamically to that table ( I did meant to say table and not GridView, please
notice that)
I can probably suggest you ine of the possible ways to do this, if you want.
Brother, it's a Mail like application. When User clicks on any row of gridview. It will read the current row ID and go to next page and will show all information from database of that ID.
You can try the below code which will fire gridview's editing event when the user clicks the row or you can replace a command name of your own and handle that in gridview's rowcommand event with that command name.
Brother, it's a Mail like application. When User clicks on any row of gridview. It will read the current row ID and go to next page and will show all information from database of that ID.
I know that ... what you can do by teaking the example, is instead of just printing the message on the web page from the code-behind, you may use Response.Redirect(" url ") and pass that id as a querystring parameter. With linkbutton, I think one can do
more complicated tasks easily as it also has attributes like CommandName and CommandArgument. This is guys often come handy when you want to pass multiple parameters to the next screen and yet, do not want your users to see anything in
the URL of the target page.
ravininave
Member
158 Points
197 Posts
Get Gridview Value on Click
Dec 15, 2012 09:09 AM|LINK
I've a Gridview like:
<asp:GridView ID="Gridview1" runat="server" AutoGenerateColumns="False" GridLines ="Both"
AllowPaging ="true" ShowFooter ="true" PageSize ="10" Width="100%" CssClass="itemGrid" >
<HeaderStyle CssClass="gridhead11" />
<PagerSettings Mode="NumericFirstLast" PageButtonCount="4" FirstPageText="First" LastPageText="Last"/>
<PagerStyle CssClass="Paginator" />
<Columns>
<asp:BoundField DataField="TaskDate" ReadOnly="true" HeaderText="DATE" ItemStyle-Width="100" DataFormatString = "{0:d}">
<ItemStyle Width="100px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="TaskSubject" ReadOnly="true" HeaderText="SUBJECT" ItemStyle-Width="450" >
<ItemStyle Width="450px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="TaskFrom" ReadOnly="true" HeaderText="FROM" ItemStyle-Width="250" >
<ItemStyle Width="250px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="IsRead" ReadOnly="true" HeaderText="" ItemStyle-Width="0" >
<ItemStyle Width="0px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="TaskID" ReadOnly="true" HeaderText="" ItemStyle-Width="0" >
<ItemStyle Width="0px"></ItemStyle>
</asp:BoundField>
</Columns>
<RowStyle/>
</asp:GridView>
Now What I wish to do is when user clicks on the cell of gridview it should read the TaskID and Show Next Page which used TaskID.
SohailShaikh
Contributor
6119 Points
1167 Posts
Re: Get Gridview Value on Click
Dec 15, 2012 09:16 AM|LINK
you have to use rowcommand event check this link for more learning
http://www.aspsnippets.com/articles/asp.net-gridview---get-row-index-on-rowcommand-and-click-events.aspx
Sohail Shaikh
aarsh
Participant
1543 Points
427 Posts
Re: Get Gridview Value on Click
Dec 15, 2012 09:23 AM|LINK
If you want to do something like this : http://sdrv.ms/TQK01s. I have answered a quite similar question here : http://forums.asp.net/post/5235482.aspx. Here is the working demo for you : http://sdrv.ms/VOkLPA
ravininave
Member
158 Points
197 Posts
Re: Get Gridview Value on Click
Dec 15, 2012 09:25 AM|LINK
I'm developing Mail Like app. When user clicks on row it should show the details. I'm not using any Button or link of anything else.
aarsh
Participant
1543 Points
427 Posts
Re: Get Gridview Value on Click
Dec 15, 2012 09:32 AM|LINK
Not sure that I am clear with your clear inteions are, but you by any chance, meant to say you want to nest a table in a gridview, as I certainly would do that and add the controls dynamically to that table ( I did meant to say table and not GridView, please notice that)
I can probably suggest you ine of the possible ways to do this, if you want.
Thanks
ravininave
Member
158 Points
197 Posts
Re: Get Gridview Value on Click
Dec 15, 2012 09:35 AM|LINK
Brother, it's a Mail like application. When User clicks on any row of gridview. It will read the current row ID and go to next page and will show all information from database of that ID.
ravininave
Member
158 Points
197 Posts
Re: Get Gridview Value on Click
Dec 15, 2012 10:00 AM|LINK
I solved it like :
e.Row.Attributes("onClick") = "location.href='view.aspx?id=" & DataBinder.Eval(e.Row.DataItem, "TaskID") & "'"
thilsiva
Member
732 Points
146 Posts
Re: Get Gridview Value on Click
Dec 15, 2012 10:04 AM|LINK
Hi,
You can try the below code which will fire gridview's editing event when the user clicks the row or you can replace a command name of your own and handle that in gridview's rowcommand event with that command name.
protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs e) { try { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';"; e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';"; string jsCommand = string.Format("if ({2} != {1}) __doPostBack('{0}','Edit${1}')", Gridview1.ID, e.Row.RowIndex, Gridview1.EditIndex); } catch(Exception ex) { throw ex; } }Hope it helps
RameshRajend...
Star
7983 Points
2099 Posts
Re: Get Gridview Value on Click
Dec 15, 2012 01:19 PM|LINK
http://www.daniweb.com/web-development/aspnet/threads/259049/how-to-get-value-from-gridview-when-click-the-linkbutton
http://stackoverflow.com/questions/6295767/getting-selected-row-of-aspgridview-when-click-on-link-button-to-get-hidden-id-v
aarsh
Participant
1543 Points
427 Posts
Re: Get Gridview Value on Click
Dec 15, 2012 03:32 PM|LINK
I know that ... what you can do by teaking the example, is instead of just printing the message on the web page from the code-behind, you may use Response.Redirect(" url ") and pass that id as a querystring parameter. With linkbutton, I think one can do more complicated tasks easily as it also has attributes like CommandName and CommandArgument. This is guys often come handy when you want to pass multiple parameters to the next screen and yet, do not want your users to see anything in the URL of the target page.
But anyways ...
Thanks