Datagrid Info from a button outside the grid

ServantofGod

New Member
How can I access controls or info inside the datagrid from a button event outside the grid. I want to be able to select rows then from a button click do something with each selected row. But I can't access the elements withing the datagrid. And when I change the input to the procedure to <BR>ByVal e As DataGridCommandEventArgs it gives me a signature error. Any ideas???Hi,<BR><BR>I was playing around with a similar problem and came up with the code below. It accesses the properties of a TextBox within the DataGrid from a LinkButton which is outside the DataGrid. <BR><BR>HTH,<BR><BR>JON<BR><BR>*****************************************<BR><BR><BR><script><BR><BR> Sub FillTextBox(sender as Object, e as EventArgs)<BR> <BR> Dim tbTextBox as TextBox<BR> Dim item as DataGridItem<BR> For Each item In dg.Items<BR> If (Item.ItemType = ListItemType.EditItem) then<BR> tbTextBox = item.FindControl("tbTextBox")<BR> tbTextBox.Text = "here is some text"<BR> end if<BR> Next item<BR> <BR> End sub<BR><BR></script><BR><BR><BR><html><BR><body><BR><BR><form runat="server" name="form1" id="form1"><BR><BR><asp:LinkButton text="Fill in TextBox" runat="server" OnClick="FillTextBox" /><BR><BR><asp:DataGrid id="dg" runat="server"><BR><BR><Columns><BR><asp:TemplateColumn><BR> <EditItemTemplate><BR> <asp:TextBox id="tbTextBox" runat="server" /><BR> </EditItemTemplate><BR></asp:TemplateColumn><BR></Columns><BR><BR></asp:dataGrid><BR><BR></form><BR></body><BR></html>That is it. Exactly what I needed. I have a checkbox and now someone can select any row in the grid with a checkbox and hit submit then I can put in the db that they selected it. <BR>Thanks a lot. I didn't know I could just declare a variable as a datagriditem or datagrid or the args or anything. That will be useful.Glad to help!<BR><BR>JONYou don't happen to have an answer for this one? You sound like you have a fairly good understanding of the datagrid.<BR>http://www.aspmessageboard.com/forum/aspplus.asp?M=379248&F=36&P=1I'll think about it, but no ideas for now! Actually I'm far from being a DataGrid expert (or any other kind of expert) - you just lucked out that I'd had exactly the same problem as you!<BR><BR>JON
 
Back
Top