Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datalist in Datagrid

Status
Not open for further replies.

ISPrincess

Programmer
Feb 22, 2002
318
US
I have imbedded a datalist control in my Datagrid.

This datalist is made up of Linkbuttons. HTML Below. (sorry about the formatting)

Code:
<asp:templatecolumn headertext="From Facility">
     <ItemTemplate>
         <asp:datalist id="dlFacilities" Runat="server" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4" ShowHeader="False" RepeatDirection="Horizontal" BackColor="White" DataKeyField="FacilityCodeID" OnItemCommand="dlFacilities_ItemCommand" OnItemDataBound="dlFacilities_ItemDataBound">
         <ItemStyle Wrap="False" />
         <ItemTemplate>
              <asp:linkbutton id="lnkFacility"  runat="server" commandname="Submit" commandargument='<%# DataBinder.Eval(Container, "DataItem.FacilityCodeID")%>'>
                     <%# DataBinder.Eval(Container, "DataItem.Name")%>
						</asp:linkbutton>
         </ItemTemplate>
          </asp:datalist>
          </ItemTemplate>
</asp:templatecolumn>

On the ItemCommand of the imbedded list, the code will need to perform some procedure. This procedure needs to know the datakey of the parent control: the datagrid. The item is not selected in the datagrid.

Any ideas on how to capture the datakey of the parent datagrid in the itemcommand of the imbedded datalist?

PH
I was walking home one night and a guy hammering on a roof called me a paranoid little weirdo.
In morse code.
-Emo Phillips
 
Isn't the DataList being bound during the ItemDataBound event of it's parent DataGrid? If so, you can start out with the event of the DataGrid ItemDataBound first, and get the datakey then. Now bind the child object (DataList).

Make sense?

Greetings,
Dragonwell
 
Kind of makes sense, but it IS Monday.

I understand that I will get the datakey of the parent control on the ItemDataBound, but then what do I do with that value in order to persist it until the ItemCommand of the imbedded datalist?

Is there anyway you could show me a very simple example?

PH
I was walking home one night and a guy hammering on a roof called me a paranoid little weirdo.
In morse code.
-Emo Phillips
 
Code:
DataGrid1_OnItemDataBound(object sender, EventArgs e){
    
    [green]//get the DataKey for this row[/green]
    int facilityCodeID;
    facilityCodeID = (int)DataGrid1.DataKeys[e.ItemIndex];

    [green]
    //now you have the parameter for the sp.

    //Now, get a reference to the DataList for this row.[/green]
    DataList dlFacilities;
    dlFacilities = (DataList)e.Item.FindControl("dlFacilities");
    [green]
    //bind it to the result of your sp[/green]
    dlFacilities.DataSource = YouDataMethod(faciltyCodeID);
    dlFacilities.DataBind();

}

Greetings,
Dragonwell
 
How do I know what this is:

int facilityCodeID;
facilityCodeID = (int)DataGrid1.DataKeys[e.ItemIndex];


On this event:
Sub dlFacilities_ItemCommand(ByVal sender As Object, ByVal e As DataListCommandEventArgs)




PH
I was walking home one night and a guy hammering on a roof called me a paranoid little weirdo.
In morse code.
-Emo Phillips
 
sorry about that - misunderstood. shouldn't/couldn't each row if the dlFacilities datasource have that in it?

Greetings,
Dragonwell
 
It does not. Of course, I can add that to binding if you think that is the only way to get that value.

Thank you for your help and for sticking with me.



PH
I was walking home one night and a guy hammering on a roof called me a paranoid little weirdo.
In morse code.
-Emo Phillips
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top