Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
My website is based on ONLINE Shopping

I have GridView with connected with sqlDataSource have table name ITEMTYPE(which has list of SUBitems)

This grid view which show CATEGORY....
Code:::

XML
<asp:GridView ID="GridViewCategory" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSourceCat"
                            Width="311px" GridLines="None">
                            <Columns>
                                <asp:TemplateField>
                                    <ItemTemplate>
                                        <asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Eval("itemType") %>' OnClick="LinkButton1_Click"
                                            CssClass="decoration"></asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>


I want to get corresponding ID and stored it session n pass it to new page

which show list of product corresponding to that id..
Posted
Updated 22-Oct-10 19:23pm
v2
Comments
Bikash Shrestha From Nepal 22-Oct-10 8:27am    
please make yourself clear

CSS
these links will surely help You:
"http://msdn.microsoft.com/en-us/library/aa581796.aspx">Link 1
"http://msdn.microsoft.com/en-us/library/aa479344.aspx">Link 2
 
Share this answer
 
Comments
Bikash Shrestha From Nepal 23-Oct-10 11:13am    
please vote me if it helped You
Use DeleteCommand And set Datakeys name as Id
& Change The name of command as show details or as per ur choice.
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string str = GridView2.DataKeys[e.RowIndex].Value.ToString();
Session["ID"]=str;
or u can use it in querystring
as
Response.Redirect("abc.aspx?+str");
}
 
Share this answer
 
v3
you can use GridView RowCommand event

check this sample
GridView.RowCommand Event[^]
 
Share this answer
 
Comments
Ankur\m/ 23-Oct-10 1:24am    
[moved from answer]
Vineet_2109 wrote:
i tried but not working as if it show an error of "Input string was not in a correct format." it is bounded with the string datatype in the table..

I want corresponding ID on which it click button from database..

My table


itemID itemType

1 Fiction
2 Non Fiction
3 Music

this is my webPage
------------------------------------------------------
hereITEMTYPE(Category)| |
|


When itemType (category) is click give the corresponding itemID from table..



if (e.CommandName == "add")
{
int index =Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridViewCategory.Rows[index];
Label lb = new Label();
lb.Text = Server.HtmlDecode(row.Cells[1].Text);
lb.Text = index.ToString();

}
I solved in another way...


XML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSourceCat"
                           GridLines="None">
                           <Columns>
                               <asp:BoundField DataField="itemType" HeaderText="Category" SortExpression="itemType" />
                               <asp:HyperLinkField DataNavigateUrlFields="itemId" DataNavigateUrlFormatString="../ViewProduct.aspx?itemId={0}"
                                   Text="->" />
                           </Columns>
                       </asp:GridView>



N Retrive this on another Page....



Thanks guys for helping it really increased my knowledge..
 
Share this answer
 

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