P
Phani
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 ();
}
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 ();
}