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

Discussion in 'ASP .Net' started by TN Bella, Jun 17, 2004.

  1. TN Bella

    TN Bella Guest

    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, Jun 17, 2004
    #1
    1. Advertising

  2. TN Bella

    Edward Guest

    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" <>
    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" <>
    ??????:...
    > 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, Jun 18, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Teep
    Replies:
    1
    Views:
    308
    Trevor Benedict R
    Jun 17, 2004
  2. KK
    Replies:
    2
    Views:
    545
    Big Brian
    Oct 14, 2003
  3. JKop
    Replies:
    11
    Views:
    871
  4. mldardy
    Replies:
    0
    Views:
    961
    mldardy
    Sep 28, 2010
  5. Su
    Replies:
    0
    Views:
    81
Loading...

Share This Page