PDA

View Full Version : Select DataGrid Item and Fill Textboxes



gzieve
Sep 26th, 2005, 05:45 PM
I have a datagrid with bound columns. I want to select an item from a column and trigger that to fill some textboxes. This is my datagrid code on the html page.


<asp:datagrid id="DataGrid1" Width="272px" Height="32px" runat="server" OnSelectedIndexChanged="DataGrid1_Selection" BackColor="White" Font-Size="XX-Small" HorizontalAlign="Left" AutoGenerateColumns="False" Font-Names="Arial" BorderColor="#CC9999">
<selecteditemstyle backcolor="khaki"></selecteditemstyle>
<AlternatingItemStyle BackColor="#C0C0FF"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" BackColor="#8080FF"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="STUDY_CODE" HeaderText="STUDY CODE"></asp:BoundColumn>
<asp:BoundColumn DataField="START_DATE" HeaderText="MONITORING START DATE" DataFormatString="{0:MM/dd/yyyy}"></asp:BoundColumn>
<asp:BoundColumn DataField="END_DATE" HeaderText="MONITORING END DATE" DataFormatString="{0:MM/dd/yyyy}"></asp:BoundColumn>
<asp:BoundColumn DataField="PERCENT_ALLOCATION" HeaderText="PERCENT ALLOCATION"></asp:BoundColumn>
<asp:BoundColumn DataField="sites" HeaderText="SITES ASSIGNED"></asp:BoundColumn>
<asp:BoundColumn DataField="schedule" HeaderText="MONITORING SCHEDULE"></asp:BoundColumn>
</Columns>
</asp:datagrid>

This is my vb page code for the DataGrid1_Selection sub. I can't even get this far, so no idea if this is right or not.


Private Sub DataGrid1_Selection(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
TxtSites.Text = DataGrid1.SelectedItem.Cells(5).Text
TxtSchedules.Text = DataGrid1.SelectedItem.Cells(6).Text
End Sub

When I go to the page with the grid, I get a complilation error on the html page line with the "OnSelectedIndexChanged". What am I doing wrong? Thanks.

nikkiH
Sep 26th, 2005, 06:08 PM
I don't know if you want the selected event. I think you want databound.

For example, I have a grid that fills dropdowns from a column value.
I use this.
(C#)



private void dgRptSpecs_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
int FOREIGN_KEY_COL_NUM_CAT = 3;
int FOREIGN_KEY_COL_NUM_STAT = 4;
string fk;
DropDownList ddl;

// if this is a valid item, retrieve the foreign key value and select
// the proper item in the dropdown
if (e.Item.ItemType == ListItemType.AlternatingItem ||
e.Item.ItemType == ListItemType.Item)
{
// do category
fk = e.Item.Cells[FOREIGN_KEY_COL_NUM_CAT].Text;
ddl = (DropDownList) e.Item.FindControl("ddlCategory_Item");
ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByValue(fk));

// do status
fk = e.Item.Cells[FOREIGN_KEY_COL_NUM_STAT].Text;
ddl = (DropDownList) e.Item.FindControl("ddlStatus_Item");
ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByValue(fk));
}
}


Not sure though.

Oh, and for VB, you have to use the "handles" keyword for events.

i.e.
Private Sub DataGrid1_Selection(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) Handles DataGrid1.ItemSelected

sravanthi bainl
Apr 28th, 2010, 10:46 AM
I have a datagrid with bound columns. I want to select an item from a column and trigger that to fill some textboxes in jsp techonologies pl i need a fast reply its very urgent for me.






thanks in advance