Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > DataKey Field problem

Reply
Thread Tools

DataKey Field problem

 
 
Phani
Guest
Posts: n/a
 
      04-26-2005
Hi everyone !!!

I have a problem here with the DataKey
when i try to retrive the data from the DataKeys[e.Item.ItemIndex] i get
nothing out of it ...

can anyone tell me the reason for this ....plz do help me

The main thing i want to do is
display a datagrid first and then depending on the datakey value get the
data for the second datagrid from the database ..... using DAL ....

Here is the code for my thing ....
Plz help me out


<TR>
<TD><asp:datagrid id="DataGrid1" runat="server" UseAccessibleHeader="True"
AllowSorting="True" Font-Size="Smaller"
Font-Names="Tahoma" AutoGenerateColumns="False" Width="100%"
DataSource="<%# dataSet11 %>" DataKeyField="ProjectId"
DataMember="Projects">
<AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="White"
VerticalAlign="Middle"
BackColor="#6699CC"></HeaderStyle>
<Columns>
<asp:ButtonColumn Text="+" ButtonType="PushButton"
CommandName="SelectProject"></asp:ButtonColumn>
<asp:BoundColumn DataField="ProjectId" SortExpression="ProjectId"
HeaderText="Project Id"></asp:BoundColumn>
<asp:BoundColumn DataField="ProjectName" SortExpression="ProjectName"
HeaderText="Project Name"></asp:BoundColumn>
<asp:BoundColumn DataField="ProjectDescription"
SortExpression="ProjectDescription" HeaderText="Project
Description"></asp:BoundColumn>
<asp:BoundColumn DataField="ProjectStartDate"
SortExpression="ProjectStartDate" HeaderText="Start Date"></asp:BoundColumn>
</Columns>
</asp:datagrid></TD>
</TR>
<TR>
<TD><asp:datagrid id="DataGrid2" runat="server" UseAccessibleHeader="True"
AllowSorting="True" Font-Size="Smaller"
Font-Names="Tahoma" Width="100%">
<AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="White"
VerticalAlign="Middle"
BackColor="#6699CC"></HeaderStyle>
</asp:datagrid></TD>
</TR>


and this is the code behind

private void Page_Load(object sender, System.EventArgs e)
{
sqlDataAdapter1.Fill (dataSet11,"Projects");
sqlDataAdapter2.Fill (dataSet11,"Tasks");

DataColumn dc = dataSet11.Tables ["Projects"].Columns ["ProjectId"];
DataColumn dc1 = dataSet11.Tables ["Tasks"].Columns ["ProjectId"];
DataRelation dr = new DataRelation ("ProjectsTasks", dc,dc1, false);
dataSet11.Relations .Add (dr);

DataGrid1.DataSource =dataSet11;
DataGrid1.DataMember ="Projects";
DataGrid1.DataBind ();
}

private void Item_click(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
int key = Convert.ToInt32 (DataGrid1.DataKeys[e.Item.ItemIndex]);

Button1.Text =DataGrid1.DataKeys [e.Item .ItemIndex ].ToString ();
TasksDB task=new TasksDB ();
DataSet ds = task.GetTasks (key);

DataGrid2.DataSource =ds;
DataGrid2.DataBind ();
}



 
Reply With Quote
 
 
 
 
Phani
Guest
Posts: n/a
 
      04-26-2005
Hi again ....

I figured out the problem
there is a bug in ASP.Net ..... the OnItemCommand does not work for push
button .....
i changed the button type to link button and it is working fine ....

anyway thanks
Phani


 
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
javascript validation for a not required field, field is onlyrequired if another field has a value jr Javascript 3 07-08-2010 10:33 AM
Problem With DataList Datakey Anil TG ASP .Net 2 08-20-2009 06:20 AM
1.Enter space bar for field names and save the field.The field shoud not get saved and an alert should be there as"Space bars are not allowed" Sound Javascript 2 09-28-2006 02:43 PM
DataList DataKey button_click assignment Problem (DataListCommandEventArgs) Jim in Arizona ASP .Net 1 09-18-2006 06:23 PM
Datakey in Datagrid J. Ormaetxe ASP .Net 3 10-29-2003 12:54 PM



Advertisments