Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Please help!!! Need datagrid selection to fill textboxes...Need quick!! (http://www.velocityreviews.com/forums/t80786-please-help-need-datagrid-selection-to-fill-textboxes-need-quick.html)

TN Bella 06-17-2004 09:18 PM

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

Edward 06-18-2004 01:31 AM

Re: Please help!!! Need datagrid selection to fill textboxes...Need quick!!
 
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" <tina.pardi@nav-international.com>
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 --
> <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!

"TN Bella" <tina.pardi@nav-international.com>
??????:eTYXgCLVEHA.4048@TK2MSFTNGP12.phx.gbl...
> 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!





All times are GMT. The time now is 05:08 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.