Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Please help!!! Need datagrid selection to fill textboxes...Need quick!!

Reply
Thread Tools

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

 
 
TN Bella
Guest
Posts: n/a
 
      06-17-2004
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 --
<aspatagrid 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>
</aspatagrid>


-- 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!
 
Reply With Quote
 
 
 
 
Edward
Guest
Posts: n/a
 
      06-18-2004
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" <(E-Mail Removed)>
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!!


> 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 --
> <aspatagrid 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>
> </aspatagrid>
>
>
> -- 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!

"TN Bella" <(E-Mail Removed)>
??????:(E-Mail Removed)...
> 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 --
> <aspatagrid 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>
> </aspatagrid>
>
>
> -- 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!



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
need help to fill textboxes from a selected item in datagrid-selected index changed. mldardy ASP .Net 0 09-28-2010 02:59 PM
JTable with row selection, but no cell selection Simon Niederberger Java 2 01-07-2005 04:17 PM
JS comparing innerHTML to text selection (window.getSelection() /document.selection) Andrew Crowe HTML 1 09-13-2004 02:22 PM
How to change a range selection to text selection? Loebb Javascript 0 02-23-2004 02:12 PM
HOWTO autopost the selection list upon selection curiousity ASP .Net Mobile 0 11-21-2003 12:57 AM



Advertisments