D
DBLWizard
Howdy All,
I am trying to get the data from a row of a data grid in asp.net This
is a data grid with five columns (two of the hidden) as follows:
<asp:datagrid id="grdMatching" runat="server" Width="100%"
Visible="False" Height="160px" AutoGenerateColumns="False"
AllowSorting="True" onselectedindexchanged="GetRow">
<Columns>
<asp:ButtonColumn Text="Select" ButtonType="PushButton"
CommandName="Select"></asp:ButtonColumn>
<asp:TemplateColumn>
<HeaderTemplate>
Name
</HeaderTemplate>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "FullName") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn >
<HeaderTemplate>
Matches
</HeaderTemplate>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Matches") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn Visible="False">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Name") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn Visible="False">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "GivenName") %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
I am trying to use the ItemCommand event to get the data from the cells
as shown in the MSDN help but everything it comes back blank. Can
somebody tell me what I a am doing wrong? Here is the code I am using
in the ItemCommand event:
private void grdMatching_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string sConnection = "user
id=user;password=password;database=dbname;server=servername;Connect
Timeout=30";
SqlConnection myConn = new SqlConnection(sConnection);
SqlCommand myCommand;
SqlDataAdapter myDA = new SqlDataAdapter();
DataSet myDS;
string sName = "";
string sGivenName = "";
string sSql = "";
TableCell objCell = e.Item.Cells[3];
sName = objCell.Text;
objCell = e.Item.Cells[4];
sGivenName = objCell.Text;
if (sName.Length > 0 || sGivenName.Length > 0)
{
sSql = "Select top 100 InstrNum, FileType, FileDate, Book, Page,
Series, Type, Description, Series, Name, GivenName, RTrim([Name]) +
ISNULL(',' + RTrim([GivenName]), '') As [FullName] From NCLand Where
[Name] = '" + sName + "' AND [GivenName] = '" + sGivenName + " Order by
[Name], [GivenName]";
myCommand = new SqlCommand(sSql, myConn);
myDA = new SqlDataAdapter();
myDA.SelectCommand = myCommand;
myConn.Open();
myDS = new DataSet();
myDA.Fill(myDS, "SearchResults");
grdItems.DataSource = myDS.Tables["SearchResults"].DefaultView;
grdItems.DataBind();
grdItems.Visible = true;
}
}
This event fires but both cells come back with empty strings. How can
I get the data out of the cells?
Thanks
dbl
I am trying to get the data from a row of a data grid in asp.net This
is a data grid with five columns (two of the hidden) as follows:
<asp:datagrid id="grdMatching" runat="server" Width="100%"
Visible="False" Height="160px" AutoGenerateColumns="False"
AllowSorting="True" onselectedindexchanged="GetRow">
<Columns>
<asp:ButtonColumn Text="Select" ButtonType="PushButton"
CommandName="Select"></asp:ButtonColumn>
<asp:TemplateColumn>
<HeaderTemplate>
Name
</HeaderTemplate>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "FullName") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn >
<HeaderTemplate>
Matches
</HeaderTemplate>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Matches") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn Visible="False">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Name") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn Visible="False">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "GivenName") %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
I am trying to use the ItemCommand event to get the data from the cells
as shown in the MSDN help but everything it comes back blank. Can
somebody tell me what I a am doing wrong? Here is the code I am using
in the ItemCommand event:
private void grdMatching_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string sConnection = "user
id=user;password=password;database=dbname;server=servername;Connect
Timeout=30";
SqlConnection myConn = new SqlConnection(sConnection);
SqlCommand myCommand;
SqlDataAdapter myDA = new SqlDataAdapter();
DataSet myDS;
string sName = "";
string sGivenName = "";
string sSql = "";
TableCell objCell = e.Item.Cells[3];
sName = objCell.Text;
objCell = e.Item.Cells[4];
sGivenName = objCell.Text;
if (sName.Length > 0 || sGivenName.Length > 0)
{
sSql = "Select top 100 InstrNum, FileType, FileDate, Book, Page,
Series, Type, Description, Series, Name, GivenName, RTrim([Name]) +
ISNULL(',' + RTrim([GivenName]), '') As [FullName] From NCLand Where
[Name] = '" + sName + "' AND [GivenName] = '" + sGivenName + " Order by
[Name], [GivenName]";
myCommand = new SqlCommand(sSql, myConn);
myDA = new SqlDataAdapter();
myDA.SelectCommand = myCommand;
myConn.Open();
myDS = new DataSet();
myDA.Fill(myDS, "SearchResults");
grdItems.DataSource = myDS.Tables["SearchResults"].DefaultView;
grdItems.DataBind();
grdItems.Visible = true;
}
}
This event fires but both cells come back with empty strings. How can
I get the data out of the cells?
Thanks
dbl