I am currently working with a gridviews in asp.net(vb). I have it where I am able to pass information from gridview1
to gridview2
on the next page. However, what I need to do now is pass a variable from a column in gridview2
to the header of that page.
ei. in Gridview2
we have a column and all results are the same, the column header is StoreName and all the data for column 开发者_开发知识库is Sears
I know how to make the entire column invisible, but at the top of the page I need a sentence that looks like this:
Store Information for Sears
I am having trouble with what the code would look like for that line, all the thing I have tried have resulting in using a variable before it is declared. I need this line to be dynamic as the results will not always be for Sears. Any help would be greatly appreciated.
Well I think there are probably much better ways to accomplish what you're trying to do, but to answer your question, you can retrieve values from your GridView like this:
string storeName = yourGridView.Rows[rowIndex].Cells[cellIndex].Text;
Then I suppose you could do something like this:
lblYourLabel.Text = "Store Information for " + storeName;
I don't think it's a great idea to pull this information directly from your grid based on an index though. If those columns get rearranged your code no longer works. Instead pull the store name from the data that you are using to populate the grid.
If you are using a button you can pass a value through the CommandArguement
<asp:LinkButton ID="lbSelectStore" runat="server" CausesValidation="False" CommandName="Select" Text="<%# Bind("StoreName") %>" CommandArgument='<%# Eval("StoreID") %>'></asp:LinkButton>
Alternately you can just do it as a HyperLink and pass the value in the query string.
<asp:TemplateField HeaderText="Store" >
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Bind("StopeName") %>' NavigateUrl='~/StoreDetails.aspx?Store=<%# Bind("StoreID") %>'>HyperLink</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
精彩评论