Please help!!! Need datagrid selection to fill textboxes...Need quick!!

T

TN Bella

I have a datagrid populated from a SQL table that contains a checkbox,
when the user clicks on the row 3 fields from that row are than
displayed on the screen. What I NEED is for that information to populate
three textboxes so it can be send to another SQL table. Here is what my
code looks like now; can anyone help me fill the textboxes instead. I
couldn't find too much help on the subject so I am posting this
here...thanks! BTW, I am using the 1.0 .net framework.

--- when the checkbox is clicked the user clicks a button to access
this Sub ---
Sub GetItems(Source as Object, E as EventArgs)
Dim GridItem As DataGridItem
Dim chkBox as System.Web.UI.WebControls.CheckBox
Dim sName, sCode, sPay as String
For Each GridItem In MyDataGrid.Items
chkBox = GridItem.FindControl("myCheckbox")
If chkBox.Checked Then
sName=CType(GridItem.FindControl("lblName"),
Label).Text & " " & _
CType(GridItem.FindControl("lblCode"), Label).Text
sPay=GridItem.Cells(3).Text
sPay += sName & sCode & ", "
End If
Next
sPay=sPay.Substring(0,sPay.length-2)
label1.text="<b>You Chose :</b> <br>" & sPay
End Sub

-- here is my datagrid --
<asp:Datagrid id="MyDataGrid" runat="server"
AutogenerateColumns="False" BorderColor="#000000" Font-Size="8"
Font-Name="Verdana" BackColor="#E8E9D6"
AlternatingItemStyle-BackColor="#ff6633" Headerstyle-Font-Size="8"
Headerstyle-Font-Name="Verdana" Headerstyle-BackColor="#ff6633"
cellspacing="0" cellpadding="3" GridLines="Both">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="myCheckbox"
Runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Supplier Name">
<ItemTemplate>
<asp:Label id="lblName" runat="server"
text='<%# DataBinder.Eval(Container.DataItem, "splr_name") %>' />
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Supplier Code">
<ItemTemplate>
<asp:Label id="lblCode" runat="server"
text='<%# DataBinder.Eval(Container.DataItem, "supplier_cd") %>' />
</ItemTemplate>
</asp:TemplateColumn>

<asp:BoundColumn Datafield="splr_sfx"
HeaderText="Pay Point">
</asp:BoundColumn>

<asp:BoundColumn Datafield="splr_addr"
HeaderText="Address">
</asp:BoundColumn>

<asp:BoundColumn Datafield="splr_city"
HeaderText="City">
</asp:BoundColumn>

<asp:BoundColumn Datafield="splr_state"
HeaderText="State">
</asp:BoundColumn>

</Columns>
</asp:Datagrid>


-- Here are the textboxes I want to fill --
<asp:TextBox id="txtSupName" runat="server"></asp:TextBox>
<asp:TextBox id="txtSupCD" runat="server"></asp:TextBox>
&nbsp;&nbsp;&nbsp;
<asp:TextBox id="txtSupsfx" runat="server"></asp:TextBox>



*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
E

Edward

I prefer to use SelectedIndexChanged event of DataGrid, if you still want
to use template item, you'd better use radio button , that will best declare
what you need.

in DataGrid definition, OnSelectedIndexChanged="TheEvent_Handler" should be
added.

void TheEvent_Handler( Object sender, System.EventArgs e ) {
// grid.DataKeys[grid.SelectedIndex] can give your the key field
of current selected row;
// grid.SelectedIndex give your current index in DataGrid Items
// so you can use DataGrid.Items, to get the value of column a,b,c
then fill your textbox.
}

sometime DataGrid is a good choice, but sometime, you should try to DIY,
because not all the end-users of our system would praise DataGrid.

----- Original Message -----
From: "TN Bella" <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Sent: Friday, June 18, 2004 5:18 AM
Subject: Please help!!! Need datagrid selection to fill textboxes...Need
quick!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,834
Latest member
BuyCannaLabsCBD

Latest Threads

Top