Hi
I'm having some trouble with this WebPart I am making. I am using a datagrid, and I can't figure out how to retrieve the selected value from it. I can make the event fire, but I don't know how to get the value from the selected field. Code is as follows:
namespace WebPartLibrary
{
public class SearchCustomerWP : Microsoft.SharePoint.WebPartPages.WebPart
{
//create controls
DataGrid dgView;
ButtonColumn selectableLinks;
public SearchCustomerWP()
{
//Set WebPart properties
this.Title = "WebPart: Search customer";
this.ExportMode = WebPartExportMode.All;
//Instantiate controls
dgView = new DataGrid();
selectableLinks = new ButtonColumn();
//Set control properties
dgView.AutoGenerateColumns = false;
selectableLinks.HeaderText = "Name";
selectableLinks.ButtonType = ButtonColumnType.LinkButton;
selectableLinks.DataTextField = "Name";
selectableLinks.CommandName = "dgView_ItemCommand";
//Add links for selecting
dgView.Columns.Add(selectableLinks);
//Add event listener
dgView.ItemCommand += new DataGridCommandEventHandler(dgView_ItemCommand);
//Invoke method for filling datagrid
dgView_dataBind();
}
protected override void CreateChildControls()
{
this.Controls.Add(dgView);
ChildControlsCreated = true;
}
private void dgView_ItemCommand(object sender, DataGridCommandEventArgs e)
{
//Add label indicating the event fired
Label test = new Label();
test.Text = "DataGrid was clicked!";
this.Controls.Add(test);
}
}
}
I've left out the part with the method that sets the datasource (dgView_dataBind()), which is populated from a webservice. But the grid fills nicely and the event fires when I click the links. But I really need help on how to extract the value of the selected item. I am also uncertain if this is the best way to make this event fire, as a click on next or previous datagrid page link would also make it fire. Any comments are welcome
--
MrCrool
I'm having some trouble with this WebPart I am making. I am using a datagrid, and I can't figure out how to retrieve the selected value from it. I can make the event fire, but I don't know how to get the value from the selected field. Code is as follows:
namespace WebPartLibrary
{
public class SearchCustomerWP : Microsoft.SharePoint.WebPartPages.WebPart
{
//create controls
DataGrid dgView;
ButtonColumn selectableLinks;
public SearchCustomerWP()
{
//Set WebPart properties
this.Title = "WebPart: Search customer";
this.ExportMode = WebPartExportMode.All;
//Instantiate controls
dgView = new DataGrid();
selectableLinks = new ButtonColumn();
//Set control properties
dgView.AutoGenerateColumns = false;
selectableLinks.HeaderText = "Name";
selectableLinks.ButtonType = ButtonColumnType.LinkButton;
selectableLinks.DataTextField = "Name";
selectableLinks.CommandName = "dgView_ItemCommand";
//Add links for selecting
dgView.Columns.Add(selectableLinks);
//Add event listener
dgView.ItemCommand += new DataGridCommandEventHandler(dgView_ItemCommand);
//Invoke method for filling datagrid
dgView_dataBind();
}
protected override void CreateChildControls()
{
this.Controls.Add(dgView);
ChildControlsCreated = true;
}
private void dgView_ItemCommand(object sender, DataGridCommandEventArgs e)
{
//Add label indicating the event fired
Label test = new Label();
test.Text = "DataGrid was clicked!";
this.Controls.Add(test);
}
}
}
I've left out the part with the method that sets the datasource (dgView_dataBind()), which is populated from a webservice. But the grid fills nicely and the event fires when I click the links. But I really need help on how to extract the value of the selected item. I am also uncertain if this is the best way to make this event fire, as a click on next or previous datagrid page link would also make it fire. Any comments are welcome
--
MrCrool