Muchas gracias; os pongo el código del evento con el que cargo el DataGrid en cuestión.
Código:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click If RadioButton1.Checked = True Then Button2.Enabled = False DataGrid.CurrentPageIndex = 0 'inicializo consulta_where = "" consulta_from = "" consulta_select = "" If TextBox5.Text <> "" Then consulta_where = consulta_where & " and p.Total_Factura =" & TextBox5.Text & "" End If If TextBox4.Text <> "" consulta_where = consulta_where & "and p.Fecha_Factura =" & TextBox4.Text & "" End If If TextBox6.Text <> "" Then consulta_where = consulta_where & " p.Num_Pedido=g.Num_Pedido and g.Cuenta_Contable ='" & TextBox6.Text & "'" consulta_from = ", Inventario.dbo.Gasto_Contable g" End If If TextBox7.Text <> "" Then consulta_where = consulta_where & " and p.Doc_Contable ='" & TextBox7.Text & "'" End If If proveedor <> "" Then consulta_where = consulta_where & " and p.CodEnt_Proveedor ='" & proveedor & "'" End If 'comando.CommandText = "SELECT p.Empresa_Pide,p.Persona_Pide,p.CodEnt_Proveedor,p.Total_Factura,p.Fecha_Factura,p.Num_Pedido FROM Pedido p" & consulta_from & " where" & consulta_where comando.CommandText = "SELECT e.NomEnt as EmpresaPide, per.nomper+' '+per.ape1per+' '+per.ape2per as PersonaPide, p.CodEnt_Proveedor, p.Total_Factura, p.Fecha_Factura, p.Num_Pedido FROM Inventario.dbo.Pedido p, PruebaSISS.dbo.Entidad e, PruebaSISS.dbo.personas per" & consulta_from & " where p.Empresa_Pide=e.CodEnt and p.Persona_Pide=per.dniper" & consulta_where 'añado una columna hyperlink en el datagrid Dim Columna_Link As New HyperLinkColumn() Columna_Link.DataNavigateUrlField = "Num_Pedido" Columna_Link.DataTextField = "Num_Pedido" Columna_Link.HeaderText = "Modificar" Columna_Link.DataNavigateUrlFormatString = "Compra.aspx?numpedido={0}" Columna_Link.Target = "_blank" DataGrid.Columns.Add(Columna_Link) miadapter.SelectCommand = comando miadapter.SelectCommand.Connection = conexionInv ds.Clear() conexionInv.Open() miadapter.Fill(ds) DataGrid.DataSource = ds Session("ds") = ds DataGrid.DataBind() conexionInv.Close() ElseIf RadioButton2.Checked = True Then DataGrid.CurrentPageIndex = 0 'inicializo consulta_where = "" consulta_from = "" If DropDownList2.SelectedValue <> "" Then consulta_where = consulta_where & " and p.Persona_Pide='" & DropDownList2.SelectedValue & "'" End If If DropDownList9.SelectedValue <> "" Then consulta_where = consulta_where & " and lp.Id_Producto ='" & DropDownList9.SelectedValue & "'" End If If DropDownList8.SelectedValue <> "" Then consulta_where = consulta_where & " and lp.Cod_EntDonante ='" & DropDownList8.SelectedValue & "'" End If If DropDownList11.SelectedValue <> "" Then consulta_where = consulta_where & " and p.Empresa_Pide ='" & DropDownList11.SelectedValue & "'" End If If DropDownList12.SelectedValue <> "" Then consulta_where = consulta_where & " and lp.Cod_TipoProd ='" & DropDownList12.SelectedValue & "'" End If If DropDownList7.SelectedValue <> "" Then consulta_where = consulta_where & " and SUBSTRING (i.Cod_Proyecto,3,1)='" & DropDownList7.SelectedValue & "'" End If If DropDownList10.SelectedValue <> "" Then consulta_where = consulta_where & " and SUBSTRING (i.Cod_Proyecto,3,2)='" & DropDownList10.SelectedValue & "'" End If If DropDownList4.SelectedValue <> "" Then consulta_where = consulta_where & " and i.Cod_Proyecto='" & DropDownList4.SelectedValue & "'" End If If DropDownList1.SelectedValue <> "" Then consulta_where = consulta_where & " and i.Cod_Centro='" & DropDownList1.SelectedValue & "'" End If If TextBox3.Text <> "" Then consulta_where = consulta_where & " and i.NSerie ='" & TextBox3.Text & "'" End If If TextBox8.Text <> "" Then consulta_where = consulta_where & " and p.Fecha_Pedido =" & TextBox8.Text & "" End If If TextBox9.Text <> "" Then consulta_where = consulta_where & " and i.Etiqueta ='" & TextBox9.Text & "'" End If If RadioButtonList1.Items.Item(0).Selected = True Then consulta_where = consulta_where & " and i.Disponible = 'Si'" ElseIf RadioButtonList1.Items.Item(1).Selected = True Then consulta_where = consulta_where & " and i.Disponible = 'No'" End If comando.CommandText = "SELECT i.Etiqueta,p.Num_Pedido,p.CodEnt_Proveedor,tp.Descripcion as Tipo_Producto,i.Disponible,i.Fecha_Baja,pro.DesPro as Proyecto,lp.Foto,p.Fecha_Pedido,e.NomEnt as EntDonante FROM PruebaSISS.dbo.proyecto pro, Inventario.dbo.Pedido p, Inventario.dbo.Linea_Productos lp, Inventario.dbo.Inventario i, Inventario.dbo.Tipo_Producto tp, PruebaSISS.dbo.Entidad e where p.Num_Pedido=lp.Num_Pedido and p.Num_Pedido=i.Num_Pedido and pro.CodPro=i.Cod_Proyecto and lp.Cod_TipoProd=tp.Cod_Tipo_Prod and lp.Id_Producto=tp.Cod_Ident and e.CodEnt=lp.Cod_EntDonante " & consulta_where 'añado una columna hyperlink en el datagrid Dim Columna_Link As New HyperLinkColumn() Columna_Link.DataNavigateUrlField = "Num_Pedido" Columna_Link.DataTextField = "Num_Pedido" Columna_Link.HeaderText = "Modificar" Columna_Link.DataNavigateUrlFormatString = "Compra.aspx?numpedido={0}" Columna_Link.Target = "_blank" DataGrid.Columns.Add(Columna_Link) 'añado una columna hyperlink en el datagrid Dim Columna_Link2 As New HyperLinkColumn() Columna_Link2.DataNavigateUrlField = "Num_Pedido" Columna_Link2.DataTextField = "Foto" Columna_Link2.HeaderText = "Foto" Columna_Link2.DataNavigateUrlFormatString = "Foto.aspx?numpedido={0}" Columna_Link2.Target = "_blank" DataGrid.Columns.Add(Columna_Link2) Dim Boton_Link As New ButtonColumn Boton_Link.HeaderText = "Etiqueta" Boton_Link.Text = "Etiqueta" Boton_Link.CommandName = "Select" Boton_Link.ButtonType = ButtonColumnType.LinkButton 'Boton_Link.Visible = False DataGrid.Columns.Add(Boton_Link) miadapter.SelectCommand = comando miadapter.SelectCommand.Connection = conexionInv ds.Clear() conexionInv.Open() miadapter.Fill(ds) Session("ds") = ds DataGrid.DataSource = ds DataGrid.DataBind() conexionInv.Close() End If End Sub