M
manmit.walia
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_OnSelectedIndexChanged 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=javascript>
function OpenWindow(ul)
{
var docUrl = ul;
window.open(docUrl,
'', 'width=800,height=600,resizable=yes,menu=yes');
}
</script>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
DataKeyNames="DocID" AllowSorting="True" AutoGenerateColumns="False"
CellPadding="4" DataSourceID="GetDocs" Font-Names="Verdana"
Font-Size="8pt" ForeColor="#333333" GridLines="None"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged" Width="100%"
OnDataBound="GridView1_DataBound">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:TemplateField ItemStyle-Width="16px">
<ItemTemplate><asp:ImageButton ID="ImageButton1" Width="16" Height="16"
ImageUrl="~/images/iconbar_deletetab.gif" CommandName="Delete"
runat="server" OnClientClick="return confirm('Are you sure you want to
delete this document?');" /></ItemTemplate>
</asp:TemplateField>
<asp:ImageField HeaderText="Type" SortExpression="ContentTypeImage"
DataImageUrlField="ContentTypeImage">
<ItemStyle HorizontalAlign="Left" Width="3%" />
</asp:ImageField>
<asp:TemplateField HeaderText="Name" SortExpression="LeafName"
ItemStyle-ForeColor="#5D7B9D">
<ItemTemplate>
<asp:LinkButton ID="docLink" runat="server" Text='<%#
Bind("LeafName")%>' CommandName="Select"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Type" HeaderText="DocType"
InsertVisible="False" ReadOnly="True"
SortExpression="Type" >
<ItemStyle CssClass="InvisibleColumn" HorizontalAlign="Center"
Width="1%" />
<HeaderStyle CssClass="InvisibleColumn" />
</asp:BoundField>
<asp:BoundField DataField="CreatedDate" HeaderText="Modified"
SortExpression="CreatedDate" >
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="CreatedByUser" HeaderText="Modified By"
SortExpression="CreatedByUser" >
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="ContentSize" HeaderText="Content Size"
SortExpression="ContentSize" >
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField ItemStyle-CssClass="InvisibleColumn"
HeaderStyle-CssClass="InvisibleColumn" DataField="DocID" />
</Columns>
<RowStyle BackColor="White" ForeColor="#333333" />
<EditRowStyle BackColor="#CCCCCC" />
<SelectedRowStyle BackColor="#FFFFFF" Font-Bold="True"
ForeColor="#5D7B9D" />
<PagerStyle BackColor="#284775" ForeColor="White"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" HorizontalAlign=Left
ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
Method:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs
e)
{
int _temp1,_temp3;
string _temp2;
LinkButton lb =
(LinkButton)GridView1.SelectedRow.FindControl("docLink");
_temp1 =
Convert.ToInt32(GridView1.SelectedRow.Cells[3].Text);
_temp2 = lb.Text;
_temp3 =
Convert.ToInt32(GridView1.SelectedDataKey.Value);
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.SelectedDataKey.Value.ToString();
body.Attributes.Add(
"onclick", "OpenWindow('" + ul + "');");
}
}
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_OnSelectedIndexChanged 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=javascript>
function OpenWindow(ul)
{
var docUrl = ul;
window.open(docUrl,
'', 'width=800,height=600,resizable=yes,menu=yes');
}
</script>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
DataKeyNames="DocID" AllowSorting="True" AutoGenerateColumns="False"
CellPadding="4" DataSourceID="GetDocs" Font-Names="Verdana"
Font-Size="8pt" ForeColor="#333333" GridLines="None"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged" Width="100%"
OnDataBound="GridView1_DataBound">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:TemplateField ItemStyle-Width="16px">
<ItemTemplate><asp:ImageButton ID="ImageButton1" Width="16" Height="16"
ImageUrl="~/images/iconbar_deletetab.gif" CommandName="Delete"
runat="server" OnClientClick="return confirm('Are you sure you want to
delete this document?');" /></ItemTemplate>
</asp:TemplateField>
<asp:ImageField HeaderText="Type" SortExpression="ContentTypeImage"
DataImageUrlField="ContentTypeImage">
<ItemStyle HorizontalAlign="Left" Width="3%" />
</asp:ImageField>
<asp:TemplateField HeaderText="Name" SortExpression="LeafName"
ItemStyle-ForeColor="#5D7B9D">
<ItemTemplate>
<asp:LinkButton ID="docLink" runat="server" Text='<%#
Bind("LeafName")%>' CommandName="Select"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Type" HeaderText="DocType"
InsertVisible="False" ReadOnly="True"
SortExpression="Type" >
<ItemStyle CssClass="InvisibleColumn" HorizontalAlign="Center"
Width="1%" />
<HeaderStyle CssClass="InvisibleColumn" />
</asp:BoundField>
<asp:BoundField DataField="CreatedDate" HeaderText="Modified"
SortExpression="CreatedDate" >
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="CreatedByUser" HeaderText="Modified By"
SortExpression="CreatedByUser" >
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="ContentSize" HeaderText="Content Size"
SortExpression="ContentSize" >
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField ItemStyle-CssClass="InvisibleColumn"
HeaderStyle-CssClass="InvisibleColumn" DataField="DocID" />
</Columns>
<RowStyle BackColor="White" ForeColor="#333333" />
<EditRowStyle BackColor="#CCCCCC" />
<SelectedRowStyle BackColor="#FFFFFF" Font-Bold="True"
ForeColor="#5D7B9D" />
<PagerStyle BackColor="#284775" ForeColor="White"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" HorizontalAlign=Left
ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
Method:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs
e)
{
int _temp1,_temp3;
string _temp2;
LinkButton lb =
(LinkButton)GridView1.SelectedRow.FindControl("docLink");
_temp1 =
Convert.ToInt32(GridView1.SelectedRow.Cells[3].Text);
_temp2 = lb.Text;
_temp3 =
Convert.ToInt32(GridView1.SelectedDataKey.Value);
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.SelectedDataKey.Value.ToString();
body.Attributes.Add(
"onclick", "OpenWindow('" + ul + "');");
}
}