Hello All,
Basically What I did is create a gridview with 7 columns. One of the
columns is the LinkButton that binds it's text value to a column in my
dataset. The rest of the columns are pretty easy to see. The thing that
is not working is when I click on my linkbutton, I want to check
another column value of that row. Once I got the value, I will do two
different things based of the value. The two primary things I want to
do is either redirect the the user to another page or 'open a new
window'. I tried what ever I can think of and no luck...
Here is an example of my GridView and My
GridView_OnSele ctedIndexChange d Method. Any help would be greatfull.
The Value I want from the other column is Cell[7] of each row.
javascript:
<script type="text/javascript" language=javasc ript>
function OpenWindow(ul)
{
var docUrl = ul;
window.open(doc Url,
'', 'width=800,heig ht=600,resizabl e=yes,menu=yes' );
}
</script>
<asp:GridView ID="GridView1" runat="server" AllowPaging="Tr ue"
DataKeyNames="D ocID" AllowSorting="T rue" AutoGenerateCol umns="False"
CellPadding="4" DataSourceID="G etDocs" Font-Names="Verdana"
Font-Size="8pt" ForeColor="#333 333" GridLines="None "
OnSelectedIndex Changed="GridVi ew1_SelectedInd exChanged" Width="100%"
OnDataBound="Gr idView1_DataBou nd">
<FooterStyle BackColor="#5D7 B9D" Font-Bold="True" ForeColor="Whit e" />
<Columns>
<asp:TemplateFi eld ItemStyle-Width="16px">
<ItemTemplate>< asp:ImageButton ID="ImageButton 1" Width="16" Height="16"
ImageUrl="~/images/iconbar_deletet ab.gif" CommandName="De lete"
runat="server" OnClientClick=" return confirm('Are you sure you want to
delete this document?');" /></ItemTemplate>
</asp:TemplateFie ld>
<asp:ImageFie ld HeaderText="Typ e" SortExpression= "ContentTypeIma ge"
DataImageUrlFie ld="ContentType Image">
<ItemStyle HorizontalAlign ="Left" Width="3%" />
</asp:ImageField>
<asp:TemplateFi eld HeaderText="Nam e" SortExpression= "LeafName"
ItemStyle-ForeColor="#5D7 B9D">
<ItemTemplate >
<asp:LinkButt on ID="docLink" runat="server" Text='<%#
Bind("LeafName" )%>' CommandName="Se lect"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:BoundFie ld DataField="Type " HeaderText="Doc Type"
InsertVisible=" False" ReadOnly="True"
SortExpression= "Type" >
<ItemStyle CssClass="Invis ibleColumn" HorizontalAlign ="Center"
Width="1%" />
<HeaderStyle CssClass="Invis ibleColumn" />
</asp:BoundField>
<asp:BoundFie ld DataField="Crea tedDate" HeaderText="Mod ified"
SortExpression= "CreatedDat e" >
<ItemStyle HorizontalAlign ="Left" />
</asp:BoundField>
<asp:BoundFie ld DataField="Crea tedByUser" HeaderText="Mod ified By"
SortExpression= "CreatedByU ser" >
<ItemStyle HorizontalAlign ="Left" />
</asp:BoundField>
<asp:BoundFie ld DataField="Cont entSize" HeaderText="Con tent Size"
SortExpression= "ContentSiz e" >
<ItemStyle HorizontalAlign ="Left" />
</asp:BoundField>
<asp:BoundFie ld ItemStyle-CssClass="Invis ibleColumn"
HeaderStyle-CssClass="Invis ibleColumn" DataField="DocI D" />
</Columns>
<RowStyle BackColor="Whit e" ForeColor="#333 333" />
<EditRowStyle BackColor="#CCC CCC" />
<SelectedRowSty le BackColor="#FFF FFF" Font-Bold="True"
ForeColor="#5D7 B9D" />
<PagerStyle BackColor="#284 775" ForeColor="Whit e"
HorizontalAlign ="Center" />
<HeaderStyle BackColor="#5D7 B9D" Font-Bold="True" HorizontalAlign =Left
ForeColor="Whit e" />
<AlternatingRow Style BackColor="Whit e" ForeColor="#284 775" />
</asp:GridView>
Method:
protected void GridView1_Selec tedIndexChanged (object sender, EventArgs
e)
{
int _temp1,_temp3;
string _temp2;
LinkButton lb =
(LinkButton)Gri dView1.Selected Row.FindControl ("docLink");
_temp1 =
Convert.ToInt32 (GridView1.Sele ctedRow.Cells[3].Text);
_temp2 = lb.Text;
_temp3 =
Convert.ToInt32 (GridView1.Sele ctedDataKey.Val ue);
if (_temp1 == 1)
{
GotUrl(_temp1, _temp2, _temp3); (THIS WORKS FINE -WHICH REDIRECTS THE
USER)
}
else if(_temp1 == 0) ( NOT WORKING)
{
string ul = "DocumentViewer .aspx?DocID=" +
GridView1.Selec tedDataKey.Valu e.ToString();
body.Attributes .Add(
"onclick", "OpenWindow ('" + ul + "');");
}
}